SimulationViewProxy.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. # Copyright (c) 2018 Ultimaker B.V.
  2. # Cura is released under the terms of the LGPLv3 or higher.
  3. from PyQt5.QtCore import QObject, pyqtSignal, pyqtProperty
  4. from UM.FlameProfiler import pyqtSlot
  5. from UM.Application import Application
  6. import SimulationView
  7. class SimulationViewProxy(QObject):
  8. def __init__(self, parent=None):
  9. super().__init__(parent)
  10. self._current_layer = 0
  11. self._controller = Application.getInstance().getController()
  12. self._controller.activeViewChanged.connect(self._onActiveViewChanged)
  13. self._onActiveViewChanged()
  14. self.is_simulationView_selected = False
  15. currentLayerChanged = pyqtSignal()
  16. currentPathChanged = pyqtSignal()
  17. maxLayersChanged = pyqtSignal()
  18. maxPathsChanged = pyqtSignal()
  19. activityChanged = pyqtSignal()
  20. globalStackChanged = pyqtSignal()
  21. preferencesChanged = pyqtSignal()
  22. busyChanged = pyqtSignal()
  23. @pyqtProperty(bool, notify=activityChanged)
  24. def layerActivity(self):
  25. active_view = self._controller.getActiveView()
  26. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  27. return active_view.getActivity()
  28. return False
  29. @pyqtProperty(int, notify=maxLayersChanged)
  30. def numLayers(self):
  31. active_view = self._controller.getActiveView()
  32. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  33. return active_view.getMaxLayers()
  34. return 0
  35. @pyqtProperty(int, notify=currentLayerChanged)
  36. def currentLayer(self):
  37. active_view = self._controller.getActiveView()
  38. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  39. return active_view.getCurrentLayer()
  40. return 0
  41. @pyqtProperty(int, notify=currentLayerChanged)
  42. def minimumLayer(self):
  43. active_view = self._controller.getActiveView()
  44. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  45. return active_view.getMinimumLayer()
  46. return 0
  47. @pyqtProperty(int, notify=maxPathsChanged)
  48. def numPaths(self):
  49. active_view = self._controller.getActiveView()
  50. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  51. return active_view.getMaxPaths()
  52. return 0
  53. @pyqtProperty(int, notify=currentPathChanged)
  54. def currentPath(self):
  55. active_view = self._controller.getActiveView()
  56. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  57. return active_view.getCurrentPath()
  58. return 0
  59. @pyqtProperty(int, notify=currentPathChanged)
  60. def minimumPath(self):
  61. active_view = self._controller.getActiveView()
  62. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  63. return active_view.getMinimumPath()
  64. return 0
  65. @pyqtProperty(bool, notify=busyChanged)
  66. def busy(self):
  67. active_view = self._controller.getActiveView()
  68. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  69. return active_view.isBusy()
  70. return False
  71. @pyqtProperty(bool, notify=preferencesChanged)
  72. def compatibilityMode(self):
  73. active_view = self._controller.getActiveView()
  74. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  75. return active_view.getCompatibilityMode()
  76. return False
  77. @pyqtSlot(int)
  78. def setCurrentLayer(self, layer_num):
  79. active_view = self._controller.getActiveView()
  80. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  81. active_view.setLayer(layer_num)
  82. @pyqtSlot(int)
  83. def setMinimumLayer(self, layer_num):
  84. active_view = self._controller.getActiveView()
  85. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  86. active_view.setMinimumLayer(layer_num)
  87. @pyqtSlot(int)
  88. def setCurrentPath(self, path_num):
  89. active_view = self._controller.getActiveView()
  90. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  91. active_view.setPath(path_num)
  92. @pyqtSlot(int)
  93. def setMinimumPath(self, path_num):
  94. active_view = self._controller.getActiveView()
  95. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  96. active_view.setMinimumPath(path_num)
  97. @pyqtSlot(int)
  98. def setSimulationViewType(self, layer_view_type):
  99. active_view = self._controller.getActiveView()
  100. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  101. active_view.setSimulationViewType(layer_view_type)
  102. @pyqtSlot(result=int)
  103. def getSimulationViewType(self):
  104. active_view = self._controller.getActiveView()
  105. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  106. return active_view.getSimulationViewType()
  107. return 0
  108. @pyqtSlot(bool)
  109. def setSimulationRunning(self, running):
  110. active_view = self._controller.getActiveView()
  111. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  112. active_view.setSimulationRunning(running)
  113. @pyqtSlot(result=bool)
  114. def getSimulationRunning(self):
  115. active_view = self._controller.getActiveView()
  116. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  117. return active_view.isSimulationRunning()
  118. return False
  119. @pyqtSlot(result=float)
  120. def getMinFeedrate(self):
  121. active_view = self._controller.getActiveView()
  122. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  123. return active_view.getMinFeedrate()
  124. return 0
  125. @pyqtSlot(result=float)
  126. def getMaxFeedrate(self):
  127. active_view = self._controller.getActiveView()
  128. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  129. return active_view.getMaxFeedrate()
  130. return 0
  131. @pyqtSlot(result=float)
  132. def getMinThickness(self):
  133. active_view = self._controller.getActiveView()
  134. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  135. return active_view.getMinThickness()
  136. return 0
  137. @pyqtSlot(result=float)
  138. def getMaxThickness(self):
  139. active_view = self._controller.getActiveView()
  140. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  141. return active_view.getMaxThickness()
  142. return 0
  143. # Opacity 0..1
  144. @pyqtSlot(int, float)
  145. def setExtruderOpacity(self, extruder_nr, opacity):
  146. active_view = self._controller.getActiveView()
  147. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  148. active_view.setExtruderOpacity(extruder_nr, opacity)
  149. @pyqtSlot(int)
  150. def setShowTravelMoves(self, show):
  151. active_view = self._controller.getActiveView()
  152. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  153. active_view.setShowTravelMoves(show)
  154. @pyqtSlot(int)
  155. def setShowHelpers(self, show):
  156. active_view = self._controller.getActiveView()
  157. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  158. active_view.setShowHelpers(show)
  159. @pyqtSlot(int)
  160. def setShowSkin(self, show):
  161. active_view = self._controller.getActiveView()
  162. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  163. active_view.setShowSkin(show)
  164. @pyqtSlot(int)
  165. def setShowInfill(self, show):
  166. active_view = self._controller.getActiveView()
  167. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  168. active_view.setShowInfill(show)
  169. @pyqtProperty(int, notify=globalStackChanged)
  170. def extruderCount(self):
  171. active_view = self._controller.getActiveView()
  172. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  173. return active_view.getExtruderCount()
  174. return 0
  175. def _layerActivityChanged(self):
  176. self.activityChanged.emit()
  177. def _onLayerChanged(self):
  178. self.currentLayerChanged.emit()
  179. self._layerActivityChanged()
  180. def _onPathChanged(self):
  181. self.currentPathChanged.emit()
  182. self._layerActivityChanged()
  183. def _onMaxLayersChanged(self):
  184. self.maxLayersChanged.emit()
  185. def _onMaxPathsChanged(self):
  186. self.maxPathsChanged.emit()
  187. def _onBusyChanged(self):
  188. self.busyChanged.emit()
  189. def _onActivityChanged(self):
  190. self.activityChanged.emit()
  191. def _onGlobalStackChanged(self):
  192. self.globalStackChanged.emit()
  193. def _onPreferencesChanged(self):
  194. self.preferencesChanged.emit()
  195. def _onActiveViewChanged(self):
  196. active_view = self._controller.getActiveView()
  197. if isinstance(active_view, SimulationView.SimulationView.SimulationView):
  198. # remove other connection if once the SimulationView was created.
  199. if self.is_simulationView_selected:
  200. active_view.currentLayerNumChanged.disconnect(self._onLayerChanged)
  201. active_view.currentPathNumChanged.disconnect(self._onPathChanged)
  202. active_view.maxLayersChanged.disconnect(self._onMaxLayersChanged)
  203. active_view.maxPathsChanged.disconnect(self._onMaxPathsChanged)
  204. active_view.busyChanged.disconnect(self._onBusyChanged)
  205. active_view.activityChanged.disconnect(self._onActivityChanged)
  206. active_view.globalStackChanged.disconnect(self._onGlobalStackChanged)
  207. active_view.preferencesChanged.disconnect(self._onPreferencesChanged)
  208. self.is_simulationView_selected = True
  209. active_view.currentLayerNumChanged.connect(self._onLayerChanged)
  210. active_view.currentPathNumChanged.connect(self._onPathChanged)
  211. active_view.maxLayersChanged.connect(self._onMaxLayersChanged)
  212. active_view.maxPathsChanged.connect(self._onMaxPathsChanged)
  213. active_view.busyChanged.connect(self._onBusyChanged)
  214. active_view.activityChanged.connect(self._onActivityChanged)
  215. active_view.globalStackChanged.connect(self._onGlobalStackChanged)
  216. active_view.preferencesChanged.connect(self._onPreferencesChanged)