SimulationViewProxy.py 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. # Copyright (c) 2021 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from typing import TYPE_CHECKING
  4. from PyQt6.QtCore import QObject, pyqtSignal, pyqtProperty
  5. from UM.FlameProfiler import pyqtSlot
  6. from UM.Application import Application
  7. if TYPE_CHECKING:
  8. from .SimulationView import SimulationView
  9. class SimulationViewProxy(QObject):
  10. def __init__(self, simulation_view: "SimulationView", parent=None) -> None:
  11. super().__init__(parent)
  12. self._simulation_view = simulation_view
  13. self._current_layer = 0
  14. self._controller = Application.getInstance().getController()
  15. self._controller.activeViewChanged.connect(self._onActiveViewChanged)
  16. self.is_simulationView_selected = False
  17. self._onActiveViewChanged()
  18. currentLayerChanged = pyqtSignal()
  19. currentPathChanged = pyqtSignal()
  20. maxLayersChanged = pyqtSignal()
  21. maxPathsChanged = pyqtSignal()
  22. activityChanged = pyqtSignal()
  23. globalStackChanged = pyqtSignal()
  24. preferencesChanged = pyqtSignal()
  25. busyChanged = pyqtSignal()
  26. colorSchemeLimitsChanged = pyqtSignal()
  27. @pyqtProperty(bool, notify=activityChanged)
  28. def layerActivity(self):
  29. return self._simulation_view.getActivity()
  30. @pyqtProperty(int, notify=maxLayersChanged)
  31. def numLayers(self):
  32. return self._simulation_view.getMaxLayers()
  33. @pyqtProperty(int, notify=currentLayerChanged)
  34. def currentLayer(self):
  35. return self._simulation_view.getCurrentLayer()
  36. @pyqtProperty(int, notify=currentLayerChanged)
  37. def minimumLayer(self):
  38. return self._simulation_view.getMinimumLayer()
  39. @pyqtProperty(int, notify=maxPathsChanged)
  40. def numPaths(self):
  41. return self._simulation_view.getMaxPaths()
  42. @pyqtProperty(float, notify=currentPathChanged)
  43. def currentPath(self):
  44. return self._simulation_view.getCurrentPath()
  45. @pyqtSlot(float)
  46. def advanceTime(self, duration: float) -> None:
  47. self._simulation_view.advanceTime(duration)
  48. @pyqtProperty(int, notify=currentPathChanged)
  49. def minimumPath(self):
  50. return self._simulation_view.getMinimumPath()
  51. @pyqtProperty(bool, notify=busyChanged)
  52. def busy(self):
  53. return self._simulation_view.isBusy()
  54. @pyqtProperty(bool, notify=preferencesChanged)
  55. def compatibilityMode(self):
  56. return self._simulation_view.getCompatibilityMode()
  57. @pyqtProperty(int, notify=globalStackChanged)
  58. def extruderCount(self):
  59. return self._simulation_view.getExtruderCount()
  60. @pyqtSlot(int)
  61. def setCurrentLayer(self, layer_num):
  62. self._simulation_view.setLayer(layer_num)
  63. @pyqtSlot(int)
  64. def setMinimumLayer(self, layer_num):
  65. self._simulation_view.setMinimumLayer(layer_num)
  66. @pyqtSlot(float)
  67. def setCurrentPath(self, path_num: float):
  68. self._simulation_view.setPath(path_num)
  69. @pyqtSlot(int)
  70. def setMinimumPath(self, path_num):
  71. self._simulation_view.setMinimumPath(path_num)
  72. @pyqtSlot(int)
  73. def setSimulationViewType(self, layer_view_type):
  74. self._simulation_view.setSimulationViewType(layer_view_type)
  75. @pyqtSlot(result=int)
  76. def getSimulationViewType(self):
  77. return self._simulation_view.getSimulationViewType()
  78. @pyqtSlot(bool)
  79. def setSimulationRunning(self, running):
  80. self._simulation_view.setSimulationRunning(running)
  81. @pyqtSlot(result=bool)
  82. def getSimulationRunning(self):
  83. return self._simulation_view.isSimulationRunning()
  84. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  85. def minFeedrate(self):
  86. return self._simulation_view.getMinFeedrate()
  87. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  88. def maxFeedrate(self):
  89. return self._simulation_view.getMaxFeedrate()
  90. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  91. def minThickness(self):
  92. return self._simulation_view.getMinThickness()
  93. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  94. def maxThickness(self):
  95. return self._simulation_view.getMaxThickness()
  96. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  97. def maxLineWidth(self):
  98. return self._simulation_view.getMaxLineWidth()
  99. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  100. def minLineWidth(self):
  101. return self._simulation_view.getMinLineWidth()
  102. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  103. def maxFlowRate(self):
  104. return self._simulation_view.getMaxFlowRate()
  105. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  106. def minFlowRate(self):
  107. return self._simulation_view.getMinFlowRate()
  108. # Opacity 0..1
  109. @pyqtSlot(int, float)
  110. def setExtruderOpacity(self, extruder_nr, opacity):
  111. self._simulation_view.setExtruderOpacity(extruder_nr, opacity)
  112. @pyqtSlot(int)
  113. def setShowTravelMoves(self, show):
  114. self._simulation_view.setShowTravelMoves(show)
  115. @pyqtSlot(int)
  116. def setShowHelpers(self, show):
  117. self._simulation_view.setShowHelpers(show)
  118. @pyqtSlot(int)
  119. def setShowSkin(self, show):
  120. self._simulation_view.setShowSkin(show)
  121. @pyqtSlot(int)
  122. def setShowInfill(self, show):
  123. self._simulation_view.setShowInfill(show)
  124. def _layerActivityChanged(self):
  125. self.activityChanged.emit()
  126. def _onLayerChanged(self):
  127. self.currentLayerChanged.emit()
  128. self._layerActivityChanged()
  129. def _onColorSchemeLimitsChanged(self):
  130. self.colorSchemeLimitsChanged.emit()
  131. def _onPathChanged(self):
  132. self.currentPathChanged.emit()
  133. self._layerActivityChanged()
  134. scene = Application.getInstance().getController().getScene()
  135. scene.sceneChanged.emit(scene.getRoot())
  136. def _onMaxLayersChanged(self):
  137. self.maxLayersChanged.emit()
  138. def _onMaxPathsChanged(self):
  139. self.maxPathsChanged.emit()
  140. def _onBusyChanged(self):
  141. self.busyChanged.emit()
  142. def _onActivityChanged(self):
  143. self.activityChanged.emit()
  144. def _onGlobalStackChanged(self):
  145. self.globalStackChanged.emit()
  146. def _onPreferencesChanged(self):
  147. self.preferencesChanged.emit()
  148. def _onActiveViewChanged(self):
  149. active_view = self._controller.getActiveView()
  150. if active_view == self._simulation_view:
  151. self._simulation_view.currentLayerNumChanged.connect(self._onLayerChanged)
  152. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  153. self._simulation_view.currentPathNumChanged.connect(self._onPathChanged)
  154. self._simulation_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  155. self._simulation_view.maxPathsChanged.connect(self._onMaxPathsChanged)
  156. self._simulation_view.busyChanged.connect(self._onBusyChanged)
  157. self._simulation_view.activityChanged.connect(self._onActivityChanged)
  158. self._simulation_view.globalStackChanged.connect(self._onGlobalStackChanged)
  159. self._simulation_view.preferencesChanged.connect(self._onPreferencesChanged)
  160. self.is_simulationView_selected = True
  161. elif self.is_simulationView_selected:
  162. # Disconnect all of em again.
  163. self.is_simulationView_selected = False
  164. self._simulation_view.currentLayerNumChanged.disconnect(self._onLayerChanged)
  165. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  166. self._simulation_view.currentPathNumChanged.disconnect(self._onPathChanged)
  167. self._simulation_view.maxLayersChanged.disconnect(self._onMaxLayersChanged)
  168. self._simulation_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)
  169. self._simulation_view.busyChanged.disconnect(self._onBusyChanged)
  170. self._simulation_view.activityChanged.disconnect(self._onActivityChanged)
  171. self._simulation_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
  172. self._simulation_view.preferencesChanged.disconnect(self._onPreferencesChanged)