SimulationViewProxy.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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. # Opacity 0..1
  93. @pyqtSlot(int, float)
  94. def setExtruderOpacity(self, extruder_nr, opacity):
  95. self._simulation_view.setExtruderOpacity(extruder_nr, opacity)
  96. @pyqtSlot(int)
  97. def setShowTravelMoves(self, show):
  98. self._simulation_view.setShowTravelMoves(show)
  99. @pyqtSlot(int)
  100. def setShowHelpers(self, show):
  101. self._simulation_view.setShowHelpers(show)
  102. @pyqtSlot(int)
  103. def setShowSkin(self, show):
  104. self._simulation_view.setShowSkin(show)
  105. @pyqtSlot(int)
  106. def setShowInfill(self, show):
  107. self._simulation_view.setShowInfill(show)
  108. def _layerActivityChanged(self):
  109. self.activityChanged.emit()
  110. def _onLayerChanged(self):
  111. self.currentLayerChanged.emit()
  112. self._layerActivityChanged()
  113. def _onPathChanged(self):
  114. self.currentPathChanged.emit()
  115. self._layerActivityChanged()
  116. scene = Application.getInstance().getController().getScene()
  117. scene.sceneChanged.emit(scene.getRoot())
  118. def _onMaxLayersChanged(self):
  119. self.maxLayersChanged.emit()
  120. def _onMaxPathsChanged(self):
  121. self.maxPathsChanged.emit()
  122. def _onBusyChanged(self):
  123. self.busyChanged.emit()
  124. def _onActivityChanged(self):
  125. self.activityChanged.emit()
  126. def _onGlobalStackChanged(self):
  127. self.globalStackChanged.emit()
  128. def _onPreferencesChanged(self):
  129. self.preferencesChanged.emit()
  130. def _onActiveViewChanged(self):
  131. active_view = self._controller.getActiveView()
  132. if active_view == self._simulation_view:
  133. self._simulation_view.currentLayerNumChanged.connect(self._onLayerChanged)
  134. self._simulation_view.currentPathNumChanged.connect(self._onPathChanged)
  135. self._simulation_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  136. self._simulation_view.maxPathsChanged.connect(self._onMaxPathsChanged)
  137. self._simulation_view.busyChanged.connect(self._onBusyChanged)
  138. self._simulation_view.activityChanged.connect(self._onActivityChanged)
  139. self._simulation_view.globalStackChanged.connect(self._onGlobalStackChanged)
  140. self._simulation_view.preferencesChanged.connect(self._onPreferencesChanged)
  141. self.is_simulationView_selected = True
  142. elif self.is_simulationView_selected:
  143. # Disconnect all of em again.
  144. self.is_simulationView_selected = False
  145. self._simulation_view.currentLayerNumChanged.disconnect(self._onLayerChanged)
  146. self._simulation_view.currentPathNumChanged.disconnect(self._onPathChanged)
  147. self._simulation_view.maxLayersChanged.disconnect(self._onMaxLayersChanged)
  148. self._simulation_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)
  149. self._simulation_view.busyChanged.disconnect(self._onBusyChanged)
  150. self._simulation_view.activityChanged.disconnect(self._onActivityChanged)
  151. self._simulation_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
  152. self._simulation_view.preferencesChanged.disconnect(self._onPreferencesChanged)