Proof of concept for simulation

Co-authored-by: Casper Lamboo <c.lamboo@ultimaker.com>

CURA-7647
This commit is contained in:
saumya.jain 2023-12-19 10:12:56 +01:00
parent 3c550557b9
commit cfec5e0cc1
5 changed files with 128 additions and 104 deletions

View file

@ -2,7 +2,6 @@
# 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
@ -12,11 +11,6 @@ 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
@ -56,17 +50,13 @@ class SimulationViewProxy(QObject):
def numPaths(self):
return self._simulation_view.getMaxPaths()
@pyqtProperty(int, notify=currentPathChanged)
@pyqtProperty(float, notify=currentPathChanged)
def currentPath(self):
return self._simulation_view.getCurrentPath()
@pyqtProperty(int, notify=currentPathChanged)
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()) * SimulationViewProxy.FACTOR
# Since the timer cannot process time less than 1 ms, we put a lower limit here
return int(max(1, simulationTimeOfpath))
@pyqtSlot(float, result=bool)
def advanceTime(self, duration: float) -> bool:
return self._simulation_view.advanceTime(duration)
@pyqtProperty(int, notify=currentPathChanged)
def minimumPath(self):
@ -92,8 +82,8 @@ class SimulationViewProxy(QObject):
def setMinimumLayer(self, layer_num):
self._simulation_view.setMinimumLayer(layer_num)
@pyqtSlot(int)
def setCurrentPath(self, path_num):
@pyqtSlot(float)
def setCurrentPath(self, path_num: float):
self._simulation_view.setPath(path_num)
@pyqtSlot(int)
@ -229,4 +219,3 @@ class SimulationViewProxy(QObject):
self._simulation_view.activityChanged.disconnect(self._onActivityChanged)
self._simulation_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
self._simulation_view.preferencesChanged.disconnect(self._onPreferencesChanged)