mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 14:37:29 -06:00
fixing review comments. Cache only for the current layer
CURA-7647
This commit is contained in:
parent
3f8908f53a
commit
0de4f612b3
1 changed files with 12 additions and 12 deletions
|
@ -197,21 +197,22 @@ class SimulationView(CuraView):
|
||||||
left_i = 0
|
left_i = 0
|
||||||
right_i = self._max_paths - 1
|
right_i = self._max_paths - 1
|
||||||
|
|
||||||
total_duration = self.cumulativeLineDuration()
|
cumulative_line_duration = self.cumulativeLineDuration()
|
||||||
|
total_duration = cumulative_line_duration[-1]
|
||||||
|
|
||||||
# make an educated guess about where to start
|
# make an educated guess about where to start
|
||||||
i = int(right_i * max(0.0, min(1.0, self._current_time / total_duration)))
|
i = int(right_i * max(0.0, min(1.0, self._current_time / total_duration)))
|
||||||
|
|
||||||
# binary search for the correct path
|
# binary search for the correct path
|
||||||
while left_i < right_i:
|
while left_i < right_i:
|
||||||
if self._cumulative_line_duration[self.getCurrentLayer()][i] <= self._current_time:
|
if cumulative_line_duration[i] <= self._current_time:
|
||||||
left_i = i + 1
|
left_i = i + 1
|
||||||
else:
|
else:
|
||||||
right_i = i
|
right_i = i
|
||||||
i = int((left_i + right_i) / 2)
|
i = int((left_i + right_i) / 2)
|
||||||
|
|
||||||
left_value = self._cumulative_line_duration[self.getCurrentLayer()][i - 1] if i > 0 else 0.0
|
left_value = cumulative_line_duration[i - 1] if i > 0 else 0.0
|
||||||
right_value = self._cumulative_line_duration[self.getCurrentLayer()][i]
|
right_value = cumulative_line_duration[i]
|
||||||
|
|
||||||
assert (left_value <= self._current_time <= right_value)
|
assert (left_value <= self._current_time <= right_value)
|
||||||
|
|
||||||
|
@ -226,7 +227,7 @@ class SimulationView(CuraView):
|
||||||
:param time_increase: The amount of time to advance (in seconds).
|
: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.
|
:return: True if the time was advanced, False if the end of the simulation was reached.
|
||||||
"""
|
"""
|
||||||
total_duration = self.cumulativeLineDuration()
|
total_duration = self.cumulativeLineDuration()[-1]
|
||||||
|
|
||||||
if self._current_time + time_increase > total_duration:
|
if self._current_time + time_increase > total_duration:
|
||||||
# If we have reached the end of the simulation, go to the next layer.
|
# If we have reached the end of the simulation, go to the next layer.
|
||||||
|
@ -242,9 +243,11 @@ class SimulationView(CuraView):
|
||||||
self.setTime(self._current_time + time_increase)
|
self.setTime(self._current_time + time_increase)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def cumulativeLineDuration(self) -> float:
|
def cumulativeLineDuration(self) -> list:
|
||||||
# Make sure _cumulative_line_duration is initialized properly
|
# Make sure _cumulative_line_duration is initialized properly
|
||||||
if self.getCurrentLayer() not in self._cumulative_line_duration:
|
if self.getCurrentLayer() not in self._cumulative_line_duration:
|
||||||
|
#clear cache
|
||||||
|
self._cumulative_line_duration = {}
|
||||||
self._cumulative_line_duration[self.getCurrentLayer()] = []
|
self._cumulative_line_duration[self.getCurrentLayer()] = []
|
||||||
total_duration = 0.0
|
total_duration = 0.0
|
||||||
for polyline in self.getLayerData().polygons:
|
for polyline in self.getLayerData().polygons:
|
||||||
|
@ -252,10 +255,7 @@ class SimulationView(CuraView):
|
||||||
total_duration += line_duration / SimulationView.SIMULATION_FACTOR
|
total_duration += line_duration / SimulationView.SIMULATION_FACTOR
|
||||||
self._cumulative_line_duration[self.getCurrentLayer()].append(total_duration)
|
self._cumulative_line_duration[self.getCurrentLayer()].append(total_duration)
|
||||||
|
|
||||||
# total duration for a layer to simulate is the last element of the list
|
return self._cumulative_line_duration[self.getCurrentLayer()]
|
||||||
total_duration = (self._cumulative_line_duration[self.getCurrentLayer()][-1])
|
|
||||||
|
|
||||||
return total_duration
|
|
||||||
|
|
||||||
def getLayerData(self) -> Optional["LayerData"]:
|
def getLayerData(self) -> Optional["LayerData"]:
|
||||||
scene = self.getController().getScene()
|
scene = self.getController().getScene()
|
||||||
|
@ -364,8 +364,8 @@ class SimulationView(CuraView):
|
||||||
self._current_path_num = min(max(value, 0), self._max_paths)
|
self._current_path_num = min(max(value, 0), self._max_paths)
|
||||||
self._minimum_path_num = min(self._minimum_path_num, self._current_path_num)
|
self._minimum_path_num = min(self._minimum_path_num, self._current_path_num)
|
||||||
# update _current time when the path is changed by user
|
# update _current time when the path is changed by user
|
||||||
if self.getCurrentLayer() in self._cumulative_line_duration and self._current_path_num < self._max_paths and round(self._current_path_num)== self._current_path_num:
|
if self._current_path_num < self._max_paths and round(self._current_path_num)== self._current_path_num:
|
||||||
self._current_time = self._cumulative_line_duration[self.getCurrentLayer()][int(self._current_path_num)]
|
self._current_time = self.cumulativeLineDuration()[int(self._current_path_num)]
|
||||||
|
|
||||||
self._startUpdateTopLayers()
|
self._startUpdateTopLayers()
|
||||||
self.currentPathNumChanged.emit()
|
self.currentPathNumChanged.emit()
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue