From 6301926885f170f79189b0cf6fdc2d3594d1ba2e Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 7 Nov 2023 18:08:08 +0530 Subject: [PATCH 01/13] Calculating time of travel for each line segment CURA-7647 --- cura/LayerPolygon.py | 6 ++++++ plugins/SimulationView/SimulationView.py | 5 +++++ plugins/SimulationView/SimulationViewMainComponent.qml | 6 +++++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 103703e594..4eb21dd45f 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -1,5 +1,6 @@ # Copyright (c) 2019 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. +import math import numpy from typing import Optional, cast @@ -186,6 +187,11 @@ class LayerPolygon: def types(self): 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 def data(self): return self._data diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 473948bc46..88fc44df98 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -400,6 +400,9 @@ class SimulationView(CuraView): def getMaxFeedrate(self) -> float: 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: 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. @@ -524,8 +527,10 @@ class SimulationView(CuraView): 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. continue + self._visible_lengths = numpy.take(polyline.lineLengths, visible_indices) visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices) 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_with_extrusion = numpy.take(polyline.lineWidths, visible_indicies_with_extrusion) visible_thicknesses = numpy.take(polyline.lineThicknesses, visible_indices) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index a82d1e3db9..b2ef7b8356 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -136,9 +136,10 @@ Item Timer { id: simulationTimer - interval: 100 + interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) //10 //dont change running: false repeat: true + property int pathNumber : 0 onTriggered: { var currentPath = UM.SimulationView.currentPath @@ -153,10 +154,12 @@ Item if (currentPath >= numPaths) { UM.SimulationView.setCurrentPath(0) + pathNumber =0 } else { UM.SimulationView.setCurrentPath(currentPath + 1) + pathNumber = 0 } } // 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 // correctly, because part of the logic is in this trigger function. isSimulationPlaying = true + pathNumber += 1 } } From efda0aaba4329948485021bbbc4d2e365a5b63c4 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 7 Nov 2023 18:42:41 +0530 Subject: [PATCH 02/13] updated for every layer CURA-7647 --- plugins/SimulationView/SimulationView.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 88fc44df98..2f09c8018b 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -78,6 +78,8 @@ class SimulationView(CuraView): self._minimum_path_num = 0 self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged) + self._current_feedrates = {} + self._visible_lengths ={} self._busy = False self._simulation_running = False @@ -401,7 +403,7 @@ class SimulationView(CuraView): return self._max_feedrate def getSimulationTime(self) -> list: - return [length / feedrate for length, feedrate in zip(self._visible_lengths, self._current_feedrates)] + return [length / feedrate for length, feedrate in zip(self._visible_lengths[self._current_layer_num], self._current_feedrates[self._current_layer_num])] def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. @@ -527,10 +529,10 @@ class SimulationView(CuraView): 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. continue - self._visible_lengths = numpy.take(polyline.lineLengths, visible_indices) + self._visible_lengths[layer_index] = numpy.take(polyline.lineLengths, visible_indices) visible_feedrates = numpy.take(polyline.lineFeedrates, visible_indices) visible_feedrates_with_extrusion = numpy.take(polyline.lineFeedrates, visible_indicies_with_extrusion) - self._current_feedrates = visible_feedrates + self._current_feedrates[layer_index] = visible_feedrates 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) From 457cecba5943c09b1b3b5b2a573a18c0915e0bc0 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Wed, 8 Nov 2023 13:29:47 +0530 Subject: [PATCH 03/13] using numpy for array calculation CURA-7647 --- cura/LayerPolygon.py | 4 ++-- plugins/SimulationView/SimulationView.py | 2 +- plugins/SimulationView/SimulationViewMainComponent.qml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/cura/LayerPolygon.py b/cura/LayerPolygon.py index 4eb21dd45f..e5fd307dc9 100644 --- a/cura/LayerPolygon.py +++ b/cura/LayerPolygon.py @@ -189,8 +189,8 @@ class LayerPolygon: @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)] + data_array = numpy.array(self._data) + return numpy.linalg.norm(data_array[1:] - data_array[:-1], axis=1) @property def data(self): diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 2f09c8018b..18d1f981c7 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -403,7 +403,7 @@ class SimulationView(CuraView): return self._max_feedrate def getSimulationTime(self) -> list: - return [length / feedrate for length, feedrate in zip(self._visible_lengths[self._current_layer_num], self._current_feedrates[self._current_layer_num])] + return self._visible_lengths[self._current_layer_num] / self._current_feedrates[self._current_layer_num] def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index b2ef7b8356..66acff656a 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -136,7 +136,7 @@ Item Timer { id: simulationTimer - interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) //10 //dont change + interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) running: false repeat: true property int pathNumber : 0 From ce0cdd0b91f8df5a28e9bdf0bebd13c8f850bdb2 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Mon, 4 Dec 2023 17:07:43 +0100 Subject: [PATCH 04/13] =?UTF-8?q?Model=20translations=20while=20changing?= =?UTF-8?q?=20build=20plates=20while=20importing=20models,=20coordinate=20?= =?UTF-8?q?translations=20shouldn=E2=80=99t=20matter=20and=20the=20object?= =?UTF-8?q?=20should=20be=20organized=20on=20the=20plate=20where=20it=20fi?= =?UTF-8?q?nds=20space.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CURA-11166 --- cura/CuraApplication.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index c6c44cf8f5..7e2f0fb1ca 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -179,6 +179,7 @@ class CuraApplication(QtApplication): self._use_single_instance = False self._single_instance = None + self._project_mode = None self._cura_formula_functions = None # type: Optional[CuraFormulaFunctions] @@ -1845,7 +1846,7 @@ class CuraApplication(QtApplication): Logger.log("i", "Attempting to read file %s", file.toString()) if not file.isValid(): return - + self._project_mode = project_mode scene = self.getController().getScene() for node in DepthFirstIterator(scene.getRoot()): @@ -1855,16 +1856,16 @@ class CuraApplication(QtApplication): is_project_file = self.checkIsValidProjectFile(file) - if project_mode is None: - project_mode = self.getPreferences().getValue("cura/choice_on_open_project") + if self._project_mode is None: + self._project_mode = self.getPreferences().getValue("cura/choice_on_open_project") - if is_project_file and project_mode == "open_as_project": + if is_project_file and self._project_mode == "open_as_project": # open as project immediately without presenting a dialog workspace_handler = self.getWorkspaceFileHandler() workspace_handler.readLocalFile(file, add_to_recent_files_hint = add_to_recent_files) return - if is_project_file and project_mode == "always_ask": + if is_project_file and self._project_mode == "always_ask": # present a dialog asking to open as project or import models self.callLater(self.openProjectFile.emit, file, add_to_recent_files) return @@ -1999,8 +2000,11 @@ class CuraApplication(QtApplication): center_y = 0 node.translate(Vector(0, center_y, 0)) - nodes_to_arrange.append(node) + # If file extention is 3mf and models are to be loaded from a cura project, + # models are to be arranged in buildplate. + elif self._project_mode == "open_as_model": + nodes_to_arrange.append(node) # This node is deep copied from some other node which already has a BuildPlateDecorator, but the deepcopy # of BuildPlateDecorator produces one that's associated with build plate -1. So, here we need to check if From 30e4c61620fc31703cf0b4227f419beea882db30 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Wed, 6 Dec 2023 12:39:10 +0100 Subject: [PATCH 05/13] review comments fix CURA-11166 --- cura/CuraApplication.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index 7e2f0fb1ca..28dfd5e1c9 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -179,7 +179,7 @@ class CuraApplication(QtApplication): self._use_single_instance = False self._single_instance = None - self._project_mode = None + self._open_project_mode: Optional[str] = None self._cura_formula_functions = None # type: Optional[CuraFormulaFunctions] @@ -1846,7 +1846,7 @@ class CuraApplication(QtApplication): Logger.log("i", "Attempting to read file %s", file.toString()) if not file.isValid(): return - self._project_mode = project_mode + self._open_project_mode = project_mode scene = self.getController().getScene() for node in DepthFirstIterator(scene.getRoot()): @@ -1856,16 +1856,16 @@ class CuraApplication(QtApplication): is_project_file = self.checkIsValidProjectFile(file) - if self._project_mode is None: - self._project_mode = self.getPreferences().getValue("cura/choice_on_open_project") + if self._open_project_mode is None: + self._open_project_mode = self.getPreferences().getValue("cura/choice_on_open_project") - if is_project_file and self._project_mode == "open_as_project": + if is_project_file and self._open_project_mode == "open_as_project": # open as project immediately without presenting a dialog workspace_handler = self.getWorkspaceFileHandler() workspace_handler.readLocalFile(file, add_to_recent_files_hint = add_to_recent_files) return - if is_project_file and self._project_mode == "always_ask": + if is_project_file and self._open_project_mode == "always_ask": # present a dialog asking to open as project or import models self.callLater(self.openProjectFile.emit, file, add_to_recent_files) return @@ -2001,9 +2001,9 @@ class CuraApplication(QtApplication): node.translate(Vector(0, center_y, 0)) nodes_to_arrange.append(node) - # If file extention is 3mf and models are to be loaded from a cura project, - # models are to be arranged in buildplate. - elif self._project_mode == "open_as_model": + # If the file is a project,and models are to be loaded from a that project, + # models inside file should be arranged in buildplate. + elif self._open_project_mode == "open_as_model": nodes_to_arrange.append(node) # This node is deep copied from some other node which already has a BuildPlateDecorator, but the deepcopy From bf2c8b5a08e0fbf442edfa70ae4f11f04d3c32f2 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Fri, 8 Dec 2023 11:41:16 +0100 Subject: [PATCH 06/13] Simulation time fed to the timer controlling speed simulation time is made 10x faster than the actual time, for better visualisation CURA-7647 --- plugins/SimulationView/SimulationView.py | 10 ++++++---- .../SimulationViewMainComponent.qml | 6 +----- plugins/SimulationView/SimulationViewProxy.py | 15 +++++++++++++++ 3 files changed, 22 insertions(+), 9 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 18d1f981c7..6874b27625 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -79,7 +79,7 @@ class SimulationView(CuraView): self.currentLayerNumChanged.connect(self._onCurrentLayerNumChanged) self._current_feedrates = {} - self._visible_lengths ={} + self._lengths_of_polyline ={} self._busy = False self._simulation_running = False @@ -403,7 +403,9 @@ class SimulationView(CuraView): return self._max_feedrate 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: 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] if visible_indices.size == 0: # No items to take maximum or minimum of. 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_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_with_extrusion = numpy.take(polyline.lineWidths, visible_indicies_with_extrusion) visible_thicknesses = numpy.take(polyline.lineThicknesses, visible_indices) diff --git a/plugins/SimulationView/SimulationViewMainComponent.qml b/plugins/SimulationView/SimulationViewMainComponent.qml index 66acff656a..216095c15c 100644 --- a/plugins/SimulationView/SimulationViewMainComponent.qml +++ b/plugins/SimulationView/SimulationViewMainComponent.qml @@ -136,10 +136,9 @@ Item Timer { id: simulationTimer - interval: parseFloat(UM.SimulationView.getSimulationTime[pathNumber]).toFixed(2) + interval: UM.SimulationView.simulationTime running: false repeat: true - property int pathNumber : 0 onTriggered: { var currentPath = UM.SimulationView.currentPath @@ -154,12 +153,10 @@ Item if (currentPath >= numPaths) { UM.SimulationView.setCurrentPath(0) - pathNumber =0 } else { UM.SimulationView.setCurrentPath(currentPath + 1) - pathNumber = 0 } } // 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 // correctly, because part of the logic is in this trigger function. isSimulationPlaying = true - pathNumber += 1 } } diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index 669f7fdbcc..e80005fc36 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -2,9 +2,11 @@ # Cura is released under the terms of the LGPLv3 or higher. from typing import TYPE_CHECKING +import numpy from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty from UM.FlameProfiler import pyqtSlot from UM.Application import Application +from UM.Logger import Logger if TYPE_CHECKING: from .SimulationView import SimulationView @@ -54,6 +56,19 @@ class SimulationViewProxy(QObject): def currentPath(self): 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) def minimumPath(self): return self._simulation_view.getMinimumPath() From 7711c15ddedcce78e735d0a016f36e0134d3814d Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Fri, 8 Dec 2023 11:43:38 +0100 Subject: [PATCH 07/13] removed unnecessary import CURA-7647 --- plugins/SimulationView/SimulationViewProxy.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index e80005fc36..8f83e9b403 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -6,7 +6,6 @@ import numpy from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty from UM.FlameProfiler import pyqtSlot from UM.Application import Application -from UM.Logger import Logger if TYPE_CHECKING: from .SimulationView import SimulationView From a19c667106fce8ab4e6f7c7f50bd16c709d2aa51 Mon Sep 17 00:00:00 2001 From: Saumya Jain <70144862+saumyaj3@users.noreply.github.com> Date: Mon, 11 Dec 2023 14:29:33 +0100 Subject: [PATCH 08/13] Update plugins/SimulationView/SimulationViewProxy.py simplified code Co-authored-by: Casper Lamboo --- plugins/SimulationView/SimulationViewProxy.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index 8f83e9b403..e3d5ca13a7 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -64,9 +64,7 @@ class SimulationViewProxy(QObject): # 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) + return int(max(1, simulationTimeOfpath)) @pyqtProperty(int, notify=currentPathChanged) def minimumPath(self): From 189a22aa4fc9a5414424760ccab87a0418cf99d7 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 12 Dec 2023 14:56:06 +0100 Subject: [PATCH 09/13] 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)) From 3c0b9a65db5e204cecc0dcdb43d8dd59d3b1d4f0 Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 12 Dec 2023 14:59:41 +0100 Subject: [PATCH 10/13] removing commented code CURA-7647 --- plugins/SimulationView/SimulationView.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index 186036a581..cbf5e571fc 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -538,8 +538,6 @@ 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) From a9aba2df748977554a454ce3e7d7b1667d152e8d Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 12 Dec 2023 16:06:22 +0100 Subject: [PATCH 11/13] maintenence. CURA-7647 --- plugins/SimulationView/SimulationView.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/plugins/SimulationView/SimulationView.py b/plugins/SimulationView/SimulationView.py index cbf5e571fc..a659a6de97 100644 --- a/plugins/SimulationView/SimulationView.py +++ b/plugins/SimulationView/SimulationView.py @@ -402,13 +402,14 @@ class SimulationView(CuraView): def getMaxFeedrate(self) -> float: return self._max_feedrate - def getSimulationTime(self, currentIndex) -> list: + def getSimulationTime(self, currentIndex) -> float: try: - return self._lengths_of_polyline[self._current_layer_num][currentIndex] / self._current_feedrates[self._current_layer_num][currentIndex] + return (self._lengths_of_polyline[self._current_layer_num][currentIndex] / self._current_feedrates[self._current_layer_num][currentIndex])[0] + 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 + return 1.0 def getMinThickness(self) -> float: if abs(self._min_thickness - sys.float_info.max) < 10: # Some lenience due to floating point rounding. From 84565b7daa03613087b2544b78fc944e249eae3d Mon Sep 17 00:00:00 2001 From: "saumya.jain" Date: Tue, 12 Dec 2023 16:53:34 +0100 Subject: [PATCH 12/13] removal of magic number CURA-7647 --- plugins/SimulationView/SimulationViewProxy.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/plugins/SimulationView/SimulationViewProxy.py b/plugins/SimulationView/SimulationViewProxy.py index 61366fccbb..576281874c 100644 --- a/plugins/SimulationView/SimulationViewProxy.py +++ b/plugins/SimulationView/SimulationViewProxy.py @@ -12,6 +12,11 @@ if TYPE_CHECKING: class SimulationViewProxy(QObject): + + S_TO_MS = 1000 + SPEED_OF_SIMULATION = 10 + FACTOR = S_TO_MS/SPEED_OF_SIMULATION + def __init__(self, simulation_view: "SimulationView", parent=None) -> None: super().__init__(parent) self._simulation_view = simulation_view @@ -59,7 +64,7 @@ class SimulationViewProxy(QObject): def simulationTime(self): # 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(self._simulation_view.getCurrentPath()) * 100 + simulationTimeOfpath = self._simulation_view.getSimulationTime(self._simulation_view.getCurrentPath()) * SimulationViewProxy.FACTOR # Since the timer cannot process time less than 1 ms, we put a lower limit here return int(max(1, simulationTimeOfpath)) From 3472ec26a10c330cd6aea040ef70e0d6db94434d Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Tue, 12 Dec 2023 17:19:28 +0100 Subject: [PATCH 13/13] Fix snapshot for makerbot CURA-11442 --- cura/Snapshot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cura/Snapshot.py b/cura/Snapshot.py index 40c74c9693..f94b3ff42e 100644 --- a/cura/Snapshot.py +++ b/cura/Snapshot.py @@ -49,7 +49,7 @@ class Snapshot: """ if node is None: - root = Application.getInstance().getController().getScene().getRoot() + node = Application.getInstance().getController().getScene().getRoot() # the direction the camera is looking at to create the isometric view iso_view_dir = Vector(-1, -1, -1).normalized()