SimulationViewProxy.py 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 PyQt5.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(int, notify=currentPathChanged)
  43. def currentPath(self):
  44. return self._simulation_view.getCurrentPath()
  45. @pyqtProperty(int, notify=currentPathChanged)
  46. def minimumPath(self):
  47. return self._simulation_view.getMinimumPath()
  48. @pyqtProperty(bool, notify=busyChanged)
  49. def busy(self):
  50. return self._simulation_view.isBusy()
  51. @pyqtProperty(bool, notify=preferencesChanged)
  52. def compatibilityMode(self):
  53. return self._simulation_view.getCompatibilityMode()
  54. @pyqtProperty(int, notify=globalStackChanged)
  55. def extruderCount(self):
  56. return self._simulation_view.getExtruderCount()
  57. @pyqtSlot(int)
  58. def setCurrentLayer(self, layer_num):
  59. self._simulation_view.setLayer(layer_num)
  60. @pyqtSlot(int)
  61. def setMinimumLayer(self, layer_num):
  62. self._simulation_view.setMinimumLayer(layer_num)
  63. @pyqtSlot(int)
  64. def setCurrentPath(self, path_num):
  65. self._simulation_view.setPath(path_num)
  66. @pyqtSlot(int)
  67. def setMinimumPath(self, path_num):
  68. self._simulation_view.setMinimumPath(path_num)
  69. @pyqtSlot(int)
  70. def setSimulationViewType(self, layer_view_type):
  71. self._simulation_view.setSimulationViewType(layer_view_type)
  72. @pyqtSlot(result=int)
  73. def getSimulationViewType(self):
  74. return self._simulation_view.getSimulationViewType()
  75. @pyqtSlot(bool)
  76. def setSimulationRunning(self, running):
  77. self._simulation_view.setSimulationRunning(running)
  78. @pyqtSlot(result=bool)
  79. def getSimulationRunning(self):
  80. return self._simulation_view.isSimulationRunning()
  81. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  82. def minFeedrate(self):
  83. return self._simulation_view.getMinFeedrate()
  84. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  85. def maxFeedrate(self):
  86. return self._simulation_view.getMaxFeedrate()
  87. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  88. def minThickness(self):
  89. return self._simulation_view.getMinThickness()
  90. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  91. def maxThickness(self):
  92. return self._simulation_view.getMaxThickness()
  93. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  94. def maxLineWidth(self):
  95. return self._simulation_view.getMaxLineWidth()
  96. @pyqtProperty(float, notify = colorSchemeLimitsChanged)
  97. def minLineWidth(self):
  98. return self._simulation_view.getMinLineWidth()
  99. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  100. def maxFlowRate(self):
  101. return self._simulation_view.getMaxFlowRate()
  102. @pyqtProperty(float, notify=colorSchemeLimitsChanged)
  103. def minFlowRate(self):
  104. return self._simulation_view.getMinFlowRate()
  105. # Opacity 0..1
  106. @pyqtSlot(int, float)
  107. def setExtruderOpacity(self, extruder_nr, opacity):
  108. self._simulation_view.setExtruderOpacity(extruder_nr, opacity)
  109. @pyqtSlot(int)
  110. def setShowTravelMoves(self, show):
  111. self._simulation_view.setShowTravelMoves(show)
  112. @pyqtSlot(int)
  113. def setShowHelpers(self, show):
  114. self._simulation_view.setShowHelpers(show)
  115. @pyqtSlot(int)
  116. def setShowSkin(self, show):
  117. self._simulation_view.setShowSkin(show)
  118. @pyqtSlot(int)
  119. def setShowInfill(self, show):
  120. self._simulation_view.setShowInfill(show)
  121. def _layerActivityChanged(self):
  122. self.activityChanged.emit()
  123. def _onLayerChanged(self):
  124. self.currentLayerChanged.emit()
  125. self._layerActivityChanged()
  126. def _onColorSchemeLimitsChanged(self):
  127. self.colorSchemeLimitsChanged.emit()
  128. def _onPathChanged(self):
  129. self.currentPathChanged.emit()
  130. self._layerActivityChanged()
  131. scene = Application.getInstance().getController().getScene()
  132. scene.sceneChanged.emit(scene.getRoot())
  133. def _onMaxLayersChanged(self):
  134. self.maxLayersChanged.emit()
  135. def _onMaxPathsChanged(self):
  136. self.maxPathsChanged.emit()
  137. def _onBusyChanged(self):
  138. self.busyChanged.emit()
  139. def _onActivityChanged(self):
  140. self.activityChanged.emit()
  141. def _onGlobalStackChanged(self):
  142. self.globalStackChanged.emit()
  143. def _onPreferencesChanged(self):
  144. self.preferencesChanged.emit()
  145. def _onActiveViewChanged(self):
  146. active_view = self._controller.getActiveView()
  147. if active_view == self._simulation_view:
  148. self._simulation_view.currentLayerNumChanged.connect(self._onLayerChanged)
  149. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  150. self._simulation_view.currentPathNumChanged.connect(self._onPathChanged)
  151. self._simulation_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  152. self._simulation_view.maxPathsChanged.connect(self._onMaxPathsChanged)
  153. self._simulation_view.busyChanged.connect(self._onBusyChanged)
  154. self._simulation_view.activityChanged.connect(self._onActivityChanged)
  155. self._simulation_view.globalStackChanged.connect(self._onGlobalStackChanged)
  156. self._simulation_view.preferencesChanged.connect(self._onPreferencesChanged)
  157. self.is_simulationView_selected = True
  158. elif self.is_simulationView_selected:
  159. # Disconnect all of em again.
  160. self.is_simulationView_selected = False
  161. self._simulation_view.currentLayerNumChanged.disconnect(self._onLayerChanged)
  162. self._simulation_view.colorSchemeLimitsChanged.connect(self._onColorSchemeLimitsChanged)
  163. self._simulation_view.currentPathNumChanged.disconnect(self._onPathChanged)
  164. self._simulation_view.maxLayersChanged.disconnect(self._onMaxLayersChanged)
  165. self._simulation_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)
  166. self._simulation_view.busyChanged.disconnect(self._onBusyChanged)
  167. self._simulation_view.activityChanged.disconnect(self._onActivityChanged)
  168. self._simulation_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
  169. self._simulation_view.preferencesChanged.disconnect(self._onPreferencesChanged)