SimulationViewProxy.py 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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._cut_plane_flipped = 1.0
  15. self._controller = Application.getInstance().getController()
  16. self._controller.activeViewChanged.connect(self._onActiveViewChanged)
  17. self.is_simulationView_selected = False
  18. self._onActiveViewChanged()
  19. currentLayerChanged = pyqtSignal()
  20. currentPathChanged = pyqtSignal()
  21. maxLayersChanged = pyqtSignal()
  22. maxPathsChanged = pyqtSignal()
  23. activityChanged = pyqtSignal()
  24. globalStackChanged = pyqtSignal()
  25. preferencesChanged = pyqtSignal()
  26. busyChanged = pyqtSignal()
  27. colorSchemeLimitsChanged = pyqtSignal()
  28. dummySignal = pyqtSignal()
  29. @pyqtProperty(bool, notify=activityChanged)
  30. def layerActivity(self):
  31. return self._simulation_view.getActivity()
  32. @pyqtProperty(int, notify=maxLayersChanged)
  33. def numLayers(self):
  34. return self._simulation_view.getMaxLayers()
  35. @pyqtProperty(int, notify=currentLayerChanged)
  36. def currentLayer(self):
  37. return self._simulation_view.getCurrentLayer()
  38. @pyqtProperty(int, notify=currentLayerChanged)
  39. def minimumLayer(self):
  40. return self._simulation_view.getMinimumLayer()
  41. @pyqtProperty(int, notify=maxPathsChanged)
  42. def numPaths(self):
  43. return self._simulation_view.getMaxPaths()
  44. @pyqtProperty(int, notify=currentPathChanged)
  45. def currentPath(self):
  46. return self._simulation_view.getCurrentPath()
  47. @pyqtProperty(int, notify=currentPathChanged)
  48. def minimumPath(self):
  49. return self._simulation_view.getMinimumPath()
  50. @pyqtProperty(bool, notify=busyChanged)
  51. def busy(self):
  52. return self._simulation_view.isBusy()
  53. @pyqtProperty(bool, notify=preferencesChanged)
  54. def compatibilityMode(self):
  55. return self._simulation_view.getCompatibilityMode()
  56. @pyqtProperty(int, notify=globalStackChanged)
  57. def extruderCount(self):
  58. return self._simulation_view.getExtruderCount()
  59. @pyqtSlot(int)
  60. def setCurrentLayer(self, layer_num):
  61. self._simulation_view.setLayer(layer_num)
  62. @pyqtSlot(int)
  63. def setMinimumLayer(self, layer_num):
  64. self._simulation_view.setMinimumLayer(layer_num)
  65. @pyqtSlot(int)
  66. def setCurrentPath(self, path_num):
  67. self._simulation_view.setPath(path_num)
  68. @pyqtSlot(int)
  69. def setMinimumPath(self, path_num):
  70. self._simulation_view.setMinimumPath(path_num)
  71. @pyqtSlot(int)
  72. def setSimulationViewType(self, layer_view_type):
  73. self._simulation_view.setSimulationViewType(layer_view_type)
  74. @pyqtSlot(result=int)
  75. def getSimulationViewType(self):
  76. return self._simulation_view.getSimulationViewType()
  77. @pyqtSlot(bool)
  78. def setSimulationRunning(self, running):
  79. self._simulation_view.setSimulationRunning(running)
  80. @pyqtSlot(result=bool)
  81. def getSimulationRunning(self):
  82. return self._simulation_view.isSimulationRunning()
  83. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  84. def minFeedrate(self):
  85. return self._simulation_view.getMinFeedrate()
  86. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  87. def maxFeedrate(self):
  88. return self._simulation_view.getMaxFeedrate()
  89. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  90. def minThickness(self):
  91. return self._simulation_view.getMinThickness()
  92. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  93. def maxThickness(self):
  94. return self._simulation_view.getMaxThickness()
  95. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  96. def maxLineWidth(self):
  97. return self._simulation_view.getMaxLineWidth()
  98. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  99. def minLineWidth(self):
  100. return self._simulation_view.getMinLineWidth()
  101. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  102. def maxFlowRate(self):
  103. return self._simulation_view.getMaxFlowRate()
  104. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  105. def minFlowRate(self):
  106. return self._simulation_view.getMinFlowRate()
  107. # Opacity 0..1
  108. @pyqtSlot(int, float)
  109. def setExtruderOpacity(self, extruder_nr, opacity):
  110. self._simulation_view.setExtruderOpacity(extruder_nr, opacity)
  111. @pyqtSlot(int)
  112. def setShowTravelMoves(self, show):
  113. self._simulation_view.setShowTravelMoves(show)
  114. @pyqtSlot(int)
  115. def setShowHelpers(self, show):
  116. self._simulation_view.setShowHelpers(show)
  117. @pyqtSlot(int)
  118. def setShowSkin(self, show):
  119. self._simulation_view.setShowSkin(show)
  120. @pyqtSlot(int)
  121. def setShowInfill(self, show):
  122. self._simulation_view.setShowInfill(show)
  123. @pyqtProperty(int, notify=dummySignal)
  124. def buildVolumeWidth(self):
  125. return int(Application.getInstance().getBuildVolume().getWidth() * 1000.0)
  126. @pyqtProperty(int, notify=dummySignal)
  127. def buildVolumeDepth(self):
  128. return int(Application.getInstance().getBuildVolume().getDepth() * 1000.0)
  129. @pyqtSlot()
  130. def setCutPlaneOff(self):
  131. self._simulation_view.setCutPlaneEnabled(False)
  132. @pyqtSlot()
  133. def setCutPlaneX(self):
  134. self._simulation_view.setCutPlaneEnabled(True)
  135. self._simulation_view.setCutPlaneNormal([self._cut_plane_flipped * 1.0, 0.0, 0.0])
  136. @pyqtSlot()
  137. def setCutPlaneY(self):
  138. self._simulation_view.setCutPlaneEnabled(True)
  139. self._simulation_view.setCutPlaneNormal([0.0, 0.0, self._cut_plane_flipped * -1.0])
  140. @pyqtSlot()
  141. def flipCutPlane(self):
  142. self._simulation_view.setCutPlaneNormal([-x for x in self._simulation_view.getCutPlaneNormal()])
  143. @pyqtSlot(int)
  144. def setCutPlaneSlider(self, value):
  145. self._simulation_view.setCutPlaneDistance(float(value) / 1000.0)
  146. def _layerActivityChanged(self):
  147. self.activityChanged.emit()
  148. def _onLayerChanged(self):
  149. self.currentLayerChanged.emit()
  150. self._layerActivityChanged()
  151. def _onColorSchemeLimitsChanged(self):
  152. self.colorSchemeLimitsChanged.emit()
  153. def _onPathChanged(self):
  154. self.currentPathChanged.emit()
  155. self._layerActivityChanged()
  156. scene = Application.getInstance().getController().getScene()
  157. scene.sceneChanged.emit(scene.getRoot())
  158. def _onMaxLayersChanged(self):
  159. self.maxLayersChanged.emit()
  160. def _onMaxPathsChanged(self):
  161. self.maxPathsChanged.emit()
  162. def _onBusyChanged(self):
  163. self.busyChanged.emit()
  164. def _onActivityChanged(self):
  165. self.activityChanged.emit()
  166. def _onGlobalStackChanged(self):
  167. self.globalStackChanged.emit()
  168. def _onPreferencesChanged(self):
  169. self.preferencesChanged.emit()
  170. def _onActiveViewChanged(self):
  171. active_view = self._controller.getActiveView()
  172. if active_view == self._simulation_view:
  173. self._simulation_view.currentLayerNumChanged.connect(self._onLayerChanged)
  174. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  175. self._simulation_view.currentPathNumChanged.connect(self._onPathChanged)
  176. self._simulation_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  177. self._simulation_view.maxPathsChanged.connect(self._onMaxPathsChanged)
  178. self._simulation_view.busyChanged.connect(self._onBusyChanged)
  179. self._simulation_view.activityChanged.connect(self._onActivityChanged)
  180. self._simulation_view.globalStackChanged.connect(self._onGlobalStackChanged)
  181. self._simulation_view.preferencesChanged.connect(self._onPreferencesChanged)
  182. self.is_simulationView_selected = True
  183. elif self.is_simulationView_selected:
  184. # Disconnect all of em again.
  185. self.is_simulationView_selected = False
  186. self._simulation_view.currentLayerNumChanged.disconnect(self._onLayerChanged)
  187. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  188. self._simulation_view.currentPathNumChanged.disconnect(self._onPathChanged)
  189. self._simulation_view.maxLayersChanged.disconnect(self._onMaxLayersChanged)
  190. self._simulation_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)
  191. self._simulation_view.busyChanged.disconnect(self._onBusyChanged)
  192. self._simulation_view.activityChanged.disconnect(self._onActivityChanged)
  193. self._simulation_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
  194. self._simulation_view.preferencesChanged.disconnect(self._onPreferencesChanged)