From 0bb1f0b7c3ff87edbecca432e017c6423ad03eed Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 2 Jan 2024 12:05:55 +0100 Subject: [PATCH 1/2] Case of simulation with multiple extruders CURA-7647 --- plugins/SimulationView/SimulationPass.py | 22 +++++++++++----------- plugins/SimulationView/SimulationView.py | 7 +++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index dd94d678ae..cdeb9da29f 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -1,5 +1,6 @@ # Copyright (c) 2021 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import math from UM.Math.Color import Color from UM.Math.Vector import Vector @@ -148,24 +149,23 @@ class SimulationPass(RenderPass): if layer == self._layer_view._current_layer_num: # We look for the position of the head, searching the point of the current path index = int(self._layer_view.getCurrentPath()) - offset = 0 for polygon in layer_data.getLayer(layer).polygons: # The size indicates all values in the two-dimension array, and the second dimension is # always size 3 because we have 3D points. - if index >= polygon.data.size // 3 - offset: - index -= polygon.data.size // 3 - offset - offset = 1 # This is to avoid the first point when there is more than one polygon, since has the same value as the last point in the previous polygon + if index >= polygon.data.size // 3 : + index -= polygon.data.size // 3 continue # The head position is calculated and translated - ratio = self._layer_view.getCurrentPath() - index - pos_a = Vector(polygon.data[index + offset][0], polygon.data[index + offset][1], - polygon.data[index + offset][2]) - if ratio <= 0.0001 or index + offset < len(polygon.data): + ratio = self._layer_view.getCurrentPath() - math.floor(self._layer_view.getCurrentPath()) + pos_a = Vector(polygon.data[index][0], polygon.data[index + offset][1], + polygon.data[index][2]) + if ratio <= 0.0001 or index + 1 == len(polygon.data): + # in case there multiple polygons and polygon changes, the first point has the same value as the last point in the previous polygon head_position = pos_a + node.getWorldPosition() else: - pos_b = Vector(polygon.data[index + offset + 1][0], - polygon.data[index + offset + 1][1], - polygon.data[index + offset + 1][2]) + pos_b = Vector(polygon.data[index + 1][0], + polygon.data[index + 1][1], + polygon.data[index + 1][2]) vec = pos_a * (1.0 - ratio) + pos_b * ratio head_position = vec + node.getWorldPosition() break diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 337879475b..92a6a9e853 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -57,7 +57,7 @@ class SimulationView(CuraView): LAYER_VIEW_TYPE_LINE_TYPE = 1 LAYER_VIEW_TYPE_FEEDRATE = 2 LAYER_VIEW_TYPE_THICKNESS = 3 - SIMULATION_FACTOR = 3 + SIMULATION_FACTOR = 2 _no_layers_warning_preference = "view/no_layers_warning" @@ -211,7 +211,8 @@ class SimulationView(CuraView): left_value = cumulative_line_duration[i - 1] if i > 0 else 0.0 right_value = cumulative_line_duration[i] - assert (left_value <= self._current_time <= right_value) + if not (left_value <= self._current_time <= right_value): + Logger.debug(f"At index {i}: left value {left_value} right value {right_value} and current time is {self._current_time}") fractional_value = (self._current_time - left_value) / (right_value - left_value) @@ -255,6 +256,8 @@ class SimulationView(CuraView): for line_duration in list((polyline.lineLengths / polyline.lineFeedrates)[0]): total_duration += line_duration / SimulationView.SIMULATION_FACTOR self._cumulative_line_duration[self.getCurrentLayer()].append(total_duration) + # for tool change we add an extra tool path + self._cumulative_line_duration[self.getCurrentLayer()].append(total_duration) return self._cumulative_line_duration[self.getCurrentLayer()] From ee7ecc1acc76f8d5504251dba9b4627bbb3b5ca5 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Wed, 3 Jan 2024 09:16:04 +0100 Subject: [PATCH 2/2] offset removed CURA-7647 --- plugins/SimulationView/SimulationPass.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/SimulationView/SimulationPass.py b/plugins/SimulationView/SimulationPass.py index cdeb9da29f..2099f6c21d 100644 --- a/plugins/SimulationView/SimulationPass.py +++ b/plugins/SimulationView/SimulationPass.py @@ -157,7 +157,7 @@ class SimulationPass(RenderPass): continue # The head position is calculated and translated ratio = self._layer_view.getCurrentPath() - math.floor(self._layer_view.getCurrentPath()) - pos_a = Vector(polygon.data[index][0], polygon.data[index + offset][1], + pos_a = Vector(polygon.data[index][0], polygon.data[index][1], polygon.data[index][2]) if ratio <= 0.0001 or index + 1 == len(polygon.data): # in case there multiple polygons and polygon changes, the first point has the same value as the last point in the previous polygon