SimulationViewProxy.py 7.0 KB

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