From 189a22aa4fc9a5414424760ccab87a0418cf99d7 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 12 Dec 2023 14:56:06 +0100 Subject: [PATCH] refactoring of code for easier access and avoid hanging issues CURA-7647 --- plugins/SimulationView/SimulationView.py | 13 +++++++++---- plugins/SimulationView/SimulationViewProxy.py | 7 ++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 6874b27625..186036a581 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -402,10 +402,13 @@ class SimulationView(CuraView): def getMaxFeedrate(self) -> float: return self._max_feedrate - def getSimulationTime(self) -> list: - 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 getSimulationTime(self, currentIndex) -> list: + try: + return self._lengths_of_polyline[self._current_layer_num][currentIndex] / self._current_feedrates[self._current_layer_num][currentIndex] + except: + # In case of change in layers, currentIndex comes one more than the items in the lengths_of_polyline + # We give 1 second time for layer change + return 1 def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. @@ -535,6 +538,8 @@ class SimulationView(CuraView): 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] = polyline.lineFeedrates + # if len(polyline.lineLengths) > 0 and len(polyline.lineLengths) == len(polyline.lineFeedrates): + # self._simulation_time[layer_index] = polyline.lineLengths / 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/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index e3d5ca13a7..61366fccbb 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -57,12 +57,9 @@ class SimulationViewProxy(QObject): @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. + # Extracts the currents paths simulation time (in seconds) for the current path 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 + simulationTimeOfpath = self._simulation_view.getSimulationTime(self._simulation_view.getCurrentPath()) * 100 # Since the timer cannot process time less than 1 ms, we put a lower limit here return int(max(1, simulationTimeOfpath))