PrintInformation.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # Copyright (c) 2015 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from PyQt5.QtCore import QObject, QDateTime, QTimer, pyqtSignal, pyqtSlot, pyqtProperty
  4. from UM.Application import Application
  5. from UM.Resources import Resources
  6. from UM.Scene.SceneNode import SceneNode
  7. from UM.Qt.Duration import Duration
  8. import math
  9. ## A class for processing and calculating minimum, currrent and maximum print time.
  10. #
  11. # This class contains all the logic relating to calculation and slicing for the
  12. # time/quality slider concept. It is a rather tricky combination of event handling
  13. # and state management. The logic behind this is as follows:
  14. #
  15. # - A scene change or settting change event happens.
  16. # We track what the source was of the change, either a scene change, a setting change, an active machine change or something else.
  17. # - This triggers a new slice with the current settings - this is the "current settings pass".
  18. # - When the slice is done, we update the current print time and material amount.
  19. # - If the source of the slice was not a Setting change, we start the second slice pass, the "low quality settings pass". Otherwise we stop here.
  20. # - When that is done, we update the minimum print time and start the final slcice pass, the "high quality settings pass".
  21. # - When the high quality pass is done, we update the maximum print time.
  22. #
  23. class PrintInformation(QObject):
  24. class SlicePass:
  25. CurrentSettings = 1
  26. LowQualitySettings = 2
  27. HighQualitySettings = 3
  28. class SliceReason:
  29. SceneChanged = 1
  30. SettingChanged = 2
  31. ActiveMachineChanged = 3
  32. Other = 4
  33. def __init__(self, parent = None):
  34. super().__init__(parent)
  35. self._current_print_time = Duration(None, self)
  36. self._material_amount = -1
  37. self._backend = Application.getInstance().getBackend()
  38. if self._backend:
  39. self._backend.printDurationMessage.connect(self._onPrintDurationMessage)
  40. currentPrintTimeChanged = pyqtSignal()
  41. @pyqtProperty(Duration, notify = currentPrintTimeChanged)
  42. def currentPrintTime(self):
  43. return self._current_print_time
  44. materialAmountChanged = pyqtSignal()
  45. @pyqtProperty(float, notify = materialAmountChanged)
  46. def materialAmount(self):
  47. return self._material_amount
  48. def _onPrintDurationMessage(self, time, amount):
  49. #if self._slice_pass == self.SlicePass.CurrentSettings:
  50. self._current_print_time.setDuration(time)
  51. self.currentPrintTimeChanged.emit()
  52. # Material amount is sent as an amount of mm^3, so calculate length from that
  53. r = Application.getInstance().getMachineManager().getWorkingProfile().getSettingValue("material_diameter") / 2
  54. self._material_amount = round((amount / (math.pi * r ** 2)) / 1000, 2)
  55. self.materialAmountChanged.emit()