BuildVolume.py 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  1. # Copyright (c) 2016 Ultimaker B.V.
  2. # Cura is released under the terms of the AGPLv3 or higher.
  3. from cura.Settings.ExtruderManager import ExtruderManager
  4. from UM.i18n import i18nCatalog
  5. from UM.Scene.Platform import Platform
  6. from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
  7. from UM.Scene.SceneNode import SceneNode
  8. from UM.Application import Application
  9. from UM.Resources import Resources
  10. from UM.Mesh.MeshBuilder import MeshBuilder
  11. from UM.Math.Vector import Vector
  12. from UM.Math.Color import Color
  13. from UM.Math.AxisAlignedBox import AxisAlignedBox
  14. from UM.Math.Polygon import Polygon
  15. from UM.Message import Message
  16. from UM.Signal import Signal
  17. from PyQt5.QtCore import QTimer
  18. from UM.View.RenderBatch import RenderBatch
  19. from UM.View.GL.OpenGL import OpenGL
  20. catalog = i18nCatalog("cura")
  21. import numpy
  22. import copy
  23. import UM.Settings.ContainerRegistry
  24. # Setting for clearance around the prime
  25. PRIME_CLEARANCE = 1.5
  26. ## Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas.
  27. class BuildVolume(SceneNode):
  28. VolumeOutlineColor = Color(12, 169, 227, 255)
  29. raftThicknessChanged = Signal()
  30. def __init__(self, parent = None):
  31. super().__init__(parent)
  32. self._width = 0
  33. self._height = 0
  34. self._depth = 0
  35. self._shader = None
  36. self._grid_mesh = None
  37. self._grid_shader = None
  38. self._disallowed_areas = []
  39. self._disallowed_area_mesh = None
  40. self._error_areas = []
  41. self._error_mesh = None
  42. self.setCalculateBoundingBox(False)
  43. self._volume_aabb = None
  44. self._raft_thickness = 0.0
  45. self._adhesion_type = None
  46. self._platform = Platform(self)
  47. self._global_container_stack = None
  48. Application.getInstance().globalContainerStackChanged.connect(self._onStackChanged)
  49. self._onStackChanged()
  50. self._has_errors = False
  51. Application.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)
  52. # Number of objects loaded at the moment.
  53. self._number_of_objects = 0
  54. self._change_timer = QTimer()
  55. self._change_timer.setInterval(100)
  56. self._change_timer.setSingleShot(True)
  57. self._change_timer.timeout.connect(self._onChangeTimerFinished)
  58. self._build_volume_message = Message(catalog.i18nc("@info:status",
  59. "The build volume height has been reduced due to the value of the"
  60. " \"Print Sequence\" setting to prevent the gantry from colliding"
  61. " with printed models."))
  62. # Must be after setting _build_volume_message, apparently that is used in getMachineManager.
  63. # activeQualityChanged is always emitted after setActiveVariant, setActiveMaterial and setActiveQuality.
  64. # Therefore this works.
  65. Application.getInstance().getMachineManager().activeQualityChanged.connect(self._onStackChanged)
  66. # This should also ways work, and it is semantically more correct,
  67. # but it does not update the disallowed areas after material change
  68. Application.getInstance().getMachineManager().activeStackChanged.connect(self._onStackChanged)
  69. def _onSceneChanged(self, source):
  70. if self._global_container_stack:
  71. self._change_timer.start()
  72. def _onChangeTimerFinished(self):
  73. root = Application.getInstance().getController().getScene().getRoot()
  74. new_number_of_objects = len([node for node in BreadthFirstIterator(root) if node.getMeshData() and type(node) is SceneNode])
  75. if new_number_of_objects != self._number_of_objects:
  76. recalculate = False
  77. if self._global_container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
  78. recalculate = (new_number_of_objects < 2 and self._number_of_objects > 1) or (new_number_of_objects > 1 and self._number_of_objects < 2)
  79. self._number_of_objects = new_number_of_objects
  80. if recalculate:
  81. self._onSettingPropertyChanged("print_sequence", "value") # Create fake event, so right settings are triggered.
  82. def setWidth(self, width):
  83. if width: self._width = width
  84. def setHeight(self, height):
  85. if height: self._height = height
  86. def setDepth(self, depth):
  87. if depth: self._depth = depth
  88. def getDisallowedAreas(self):
  89. return self._disallowed_areas
  90. def setDisallowedAreas(self, areas):
  91. self._disallowed_areas = areas
  92. def render(self, renderer):
  93. if not self.getMeshData():
  94. return True
  95. if not self._shader:
  96. self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
  97. self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
  98. renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
  99. renderer.queueNode(self, mesh = self._grid_mesh, shader = self._grid_shader, backface_cull = True)
  100. if self._disallowed_area_mesh:
  101. renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
  102. if self._error_mesh:
  103. renderer.queueNode(self, mesh=self._error_mesh, shader=self._shader, transparent=True,
  104. backface_cull=True, sort=-8)
  105. return True
  106. ## Recalculates the build volume & disallowed areas.
  107. def rebuild(self):
  108. if not self._width or not self._height or not self._depth:
  109. return
  110. min_w = -self._width / 2
  111. max_w = self._width / 2
  112. min_h = 0.0
  113. max_h = self._height
  114. min_d = -self._depth / 2
  115. max_d = self._depth / 2
  116. mb = MeshBuilder()
  117. # Outline 'cube' of the build volume
  118. mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
  119. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor)
  120. mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
  121. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
  122. mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
  123. mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
  124. mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  125. mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  126. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
  127. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
  128. mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
  129. mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  130. self.setMeshData(mb.build())
  131. mb = MeshBuilder()
  132. mb.addQuad(
  133. Vector(min_w, min_h - 0.2, min_d),
  134. Vector(max_w, min_h - 0.2, min_d),
  135. Vector(max_w, min_h - 0.2, max_d),
  136. Vector(min_w, min_h - 0.2, max_d)
  137. )
  138. for n in range(0, 6):
  139. v = mb.getVertex(n)
  140. mb.setVertexUVCoordinates(n, v[0], v[2])
  141. self._grid_mesh = mb.build()
  142. disallowed_area_height = 0.1
  143. disallowed_area_size = 0
  144. if self._disallowed_areas:
  145. mb = MeshBuilder()
  146. color = Color(0.0, 0.0, 0.0, 0.15)
  147. for polygon in self._disallowed_areas:
  148. points = polygon.getPoints()
  149. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  150. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  151. for point in points:
  152. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d))
  153. mb.addFace(first, previous_point, new_point, color = color)
  154. previous_point = new_point
  155. # Find the largest disallowed area to exclude it from the maximum scale bounds.
  156. # This is a very nasty hack. This pretty much only works for UM machines.
  157. # This disallowed area_size needs a -lot- of rework at some point in the future: TODO
  158. if numpy.min(points[:, 1]) >= 0: # This filters out all areas that have points to the left of the centre. This is done to filter the skirt area.
  159. size = abs(numpy.max(points[:, 1]) - numpy.min(points[:, 1]))
  160. else:
  161. size = 0
  162. disallowed_area_size = max(size, disallowed_area_size)
  163. self._disallowed_area_mesh = mb.build()
  164. else:
  165. self._disallowed_area_mesh = None
  166. if self._error_areas:
  167. mb = MeshBuilder()
  168. for error_area in self._error_areas:
  169. color = Color(1.0, 0.0, 0.0, 0.5)
  170. points = error_area.getPoints()
  171. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  172. self._clamp(points[0][1], min_d, max_d))
  173. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  174. self._clamp(points[0][1], min_d, max_d))
  175. for point in points:
  176. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height,
  177. self._clamp(point[1], min_d, max_d))
  178. mb.addFace(first, previous_point, new_point, color=color)
  179. previous_point = new_point
  180. self._error_mesh = mb.build()
  181. else:
  182. self._error_mesh = None
  183. self._volume_aabb = AxisAlignedBox(
  184. minimum = Vector(min_w, min_h - 1.0, min_d),
  185. maximum = Vector(max_w, max_h - self._raft_thickness, max_d))
  186. bed_adhesion_size = self._getEdgeDisallowedSize()
  187. # As this works better for UM machines, we only add the disallowed_area_size for the z direction.
  188. # This is probably wrong in all other cases. TODO!
  189. # The +1 and -1 is added as there is always a bit of extra room required to work properly.
  190. scale_to_max_bounds = AxisAlignedBox(
  191. minimum = Vector(min_w + bed_adhesion_size + 1, min_h, min_d + disallowed_area_size - bed_adhesion_size + 1),
  192. maximum = Vector(max_w - bed_adhesion_size - 1, max_h - self._raft_thickness, max_d - disallowed_area_size + bed_adhesion_size - 1)
  193. )
  194. Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds
  195. def getBoundingBox(self):
  196. return self._volume_aabb
  197. def getRaftThickness(self):
  198. return self._raft_thickness
  199. def _updateRaftThickness(self):
  200. old_raft_thickness = self._raft_thickness
  201. self._adhesion_type = self._global_container_stack.getProperty("adhesion_type", "value")
  202. self._raft_thickness = 0.0
  203. if self._adhesion_type == "raft":
  204. self._raft_thickness = (
  205. self._global_container_stack.getProperty("raft_base_thickness", "value") +
  206. self._global_container_stack.getProperty("raft_interface_thickness", "value") +
  207. self._global_container_stack.getProperty("raft_surface_layers", "value") *
  208. self._global_container_stack.getProperty("raft_surface_thickness", "value") +
  209. self._global_container_stack.getProperty("raft_airgap", "value"))
  210. # Rounding errors do not matter, we check if raft_thickness has changed at all
  211. if old_raft_thickness != self._raft_thickness:
  212. self.setPosition(Vector(0, -self._raft_thickness, 0), SceneNode.TransformSpace.World)
  213. self.raftThicknessChanged.emit()
  214. ## Update the build volume visualization
  215. def _onStackChanged(self):
  216. if self._global_container_stack:
  217. self._global_container_stack.propertyChanged.disconnect(self._onSettingPropertyChanged)
  218. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  219. for extruder in extruders:
  220. extruder.propertyChanged.disconnect(self._onSettingPropertyChanged)
  221. self._global_container_stack = Application.getInstance().getGlobalContainerStack()
  222. if self._global_container_stack:
  223. self._global_container_stack.propertyChanged.connect(self._onSettingPropertyChanged)
  224. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  225. for extruder in extruders:
  226. extruder.propertyChanged.connect(self._onSettingPropertyChanged)
  227. self._width = self._global_container_stack.getProperty("machine_width", "value")
  228. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  229. if self._global_container_stack.getProperty("print_sequence", "value") == "one_at_a_time" and self._number_of_objects > 1:
  230. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  231. if self._height < machine_height:
  232. self._build_volume_message.show()
  233. else:
  234. self._build_volume_message.hide()
  235. else:
  236. self._height = self._global_container_stack.getProperty("machine_height", "value")
  237. self._build_volume_message.hide()
  238. self._depth = self._global_container_stack.getProperty("machine_depth", "value")
  239. self._updateDisallowedAreas()
  240. self._updateRaftThickness()
  241. self.rebuild()
  242. def _onSettingPropertyChanged(self, setting_key, property_name):
  243. if property_name != "value":
  244. return
  245. rebuild_me = False
  246. if setting_key == "print_sequence":
  247. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  248. if Application.getInstance().getGlobalContainerStack().getProperty("print_sequence", "value") == "one_at_a_time" and self._number_of_objects > 1:
  249. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  250. if self._height < machine_height:
  251. self._build_volume_message.show()
  252. else:
  253. self._build_volume_message.hide()
  254. else:
  255. self._height = self._global_container_stack.getProperty("machine_height", "value")
  256. self._build_volume_message.hide()
  257. rebuild_me = True
  258. if setting_key in self._skirt_settings or setting_key in self._prime_settings or setting_key in self._tower_settings or setting_key == "print_sequence" or setting_key in self._ooze_shield_settings or setting_key in self._distance_settings:
  259. self._updateDisallowedAreas()
  260. rebuild_me = True
  261. if setting_key in self._raft_settings:
  262. self._updateRaftThickness()
  263. rebuild_me = True
  264. if rebuild_me:
  265. self.rebuild()
  266. def hasErrors(self):
  267. return self._has_errors
  268. def _updateDisallowedAreas(self):
  269. if not self._global_container_stack:
  270. return
  271. self._has_errors = False # Reset.
  272. self._error_areas = []
  273. disallowed_areas = copy.deepcopy(
  274. self._global_container_stack.getProperty("machine_disallowed_areas", "value"))
  275. areas = []
  276. machine_width = self._global_container_stack.getProperty("machine_width", "value")
  277. machine_depth = self._global_container_stack.getProperty("machine_depth", "value")
  278. prime_tower_area = None
  279. # Add prime tower location as disallowed area.
  280. if ExtruderManager.getInstance().getResolveOrValue("prime_tower_enable") == True:
  281. prime_tower_size = self._global_container_stack.getProperty("prime_tower_size", "value")
  282. prime_tower_x = self._global_container_stack.getProperty("prime_tower_position_x", "value") - machine_width / 2
  283. prime_tower_y = - self._global_container_stack.getProperty("prime_tower_position_y", "value") + machine_depth / 2
  284. prime_tower_area = Polygon([
  285. [prime_tower_x - prime_tower_size, prime_tower_y - prime_tower_size],
  286. [prime_tower_x, prime_tower_y - prime_tower_size],
  287. [prime_tower_x, prime_tower_y],
  288. [prime_tower_x - prime_tower_size, prime_tower_y],
  289. ])
  290. disallowed_polygons = []
  291. # Check if prime positions intersect with disallowed areas
  292. prime_collision = False
  293. if disallowed_areas:
  294. for area in disallowed_areas:
  295. poly = Polygon(numpy.array(area, numpy.float32))
  296. # Minkowski with zero, to ensure that the polygon is correct & watertight.
  297. poly = poly.getMinkowskiHull(Polygon.approximatedCircle(0))
  298. disallowed_polygons.append(poly)
  299. extruder_manager = ExtruderManager.getInstance()
  300. extruders = extruder_manager.getMachineExtruders(self._global_container_stack.getId())
  301. prime_polygons = []
  302. # Each extruder has it's own prime location
  303. for extruder in extruders:
  304. prime_x = extruder.getProperty("extruder_prime_pos_x", "value") - machine_width / 2
  305. prime_y = machine_depth / 2 - extruder.getProperty("extruder_prime_pos_y", "value")
  306. prime_polygon = Polygon([
  307. [prime_x - PRIME_CLEARANCE, prime_y - PRIME_CLEARANCE],
  308. [prime_x + PRIME_CLEARANCE, prime_y - PRIME_CLEARANCE],
  309. [prime_x + PRIME_CLEARANCE, prime_y + PRIME_CLEARANCE],
  310. [prime_x - PRIME_CLEARANCE, prime_y + PRIME_CLEARANCE],
  311. ])
  312. prime_polygon = prime_polygon.getMinkowskiHull(Polygon.approximatedCircle(0))
  313. collision = False
  314. # Check if prime polygon is intersecting with any of the other disallowed areas.
  315. # Note that we check the prime area without bed adhesion.
  316. for poly in disallowed_polygons:
  317. if prime_polygon.intersectsPolygon(poly) is not None:
  318. collision = True
  319. break
  320. # Also collide with other prime positions
  321. for poly in prime_polygons:
  322. if prime_polygon.intersectsPolygon(poly) is not None:
  323. collision = True
  324. break
  325. if not collision:
  326. # Prime area is valid. Add as normal.
  327. # Once it's added like this, it will recieve a bed adhesion offset, just like the others.
  328. prime_polygons.append(prime_polygon)
  329. else:
  330. self._error_areas.append(prime_polygon)
  331. prime_collision = collision or prime_collision
  332. disallowed_polygons.extend(prime_polygons)
  333. disallowed_border_size = self._getEdgeDisallowedSize()
  334. # Extend every area already in the disallowed_areas with the skirt size.
  335. if disallowed_areas:
  336. for poly in disallowed_polygons:
  337. poly = poly.getMinkowskiHull(Polygon.approximatedCircle(disallowed_border_size))
  338. areas.append(poly)
  339. # Add the skirt areas around the borders of the build plate.
  340. if disallowed_border_size > 0:
  341. half_machine_width = self._global_container_stack.getProperty("machine_width", "value") / 2
  342. half_machine_depth = self._global_container_stack.getProperty("machine_depth", "value") / 2
  343. areas.append(Polygon(numpy.array([
  344. [-half_machine_width, -half_machine_depth],
  345. [-half_machine_width, half_machine_depth],
  346. [-half_machine_width + disallowed_border_size, half_machine_depth - disallowed_border_size],
  347. [-half_machine_width + disallowed_border_size, -half_machine_depth + disallowed_border_size]
  348. ], numpy.float32)))
  349. areas.append(Polygon(numpy.array([
  350. [half_machine_width, half_machine_depth],
  351. [half_machine_width, -half_machine_depth],
  352. [half_machine_width - disallowed_border_size, -half_machine_depth + disallowed_border_size],
  353. [half_machine_width - disallowed_border_size, half_machine_depth - disallowed_border_size]
  354. ], numpy.float32)))
  355. areas.append(Polygon(numpy.array([
  356. [-half_machine_width, half_machine_depth],
  357. [half_machine_width, half_machine_depth],
  358. [half_machine_width - disallowed_border_size, half_machine_depth - disallowed_border_size],
  359. [-half_machine_width + disallowed_border_size, half_machine_depth - disallowed_border_size]
  360. ], numpy.float32)))
  361. areas.append(Polygon(numpy.array([
  362. [half_machine_width, -half_machine_depth],
  363. [-half_machine_width, -half_machine_depth],
  364. [-half_machine_width + disallowed_border_size, -half_machine_depth + disallowed_border_size],
  365. [half_machine_width - disallowed_border_size, -half_machine_depth + disallowed_border_size]
  366. ], numpy.float32)))
  367. # Check if the prime tower area intersects with any of the other areas.
  368. # If this is the case, add it to the error area's so it can be drawn in red.
  369. # If not, add it back to disallowed area's, so it's rendered as normal.
  370. prime_tower_collision = False
  371. if prime_tower_area:
  372. # Using Minkowski of 0 fixes the prime tower area so it's rendered correctly
  373. prime_tower_area = prime_tower_area.getMinkowskiHull(Polygon.approximatedCircle(0))
  374. for area in areas:
  375. if prime_tower_area.intersectsPolygon(area) is not None:
  376. prime_tower_collision = True
  377. break
  378. if not prime_tower_collision:
  379. areas.append(prime_tower_area)
  380. else:
  381. self._error_areas.append(prime_tower_area)
  382. # The buildplate has errors if either prime tower or prime has a colission.
  383. self._has_errors = prime_tower_collision or prime_collision
  384. self._disallowed_areas = areas
  385. ## Private convenience function to get a setting from the adhesion
  386. # extruder.
  387. #
  388. # \param setting_key The key of the setting to get.
  389. # \param property The property to get from the setting.
  390. # \return The property of the specified setting in the adhesion extruder.
  391. def _getSettingFromAdhesionExtruder(self, setting_key, property = "value"):
  392. return self._getSettingFromExtruder(setting_key, "adhesion_extruder_nr", property)
  393. ## Private convenience function to get a setting from the support infill
  394. # extruder.
  395. #
  396. # \param setting_key The key of the setting to get.
  397. # \param property The property to get from the setting.
  398. # \return The property of the specified setting in the support infill
  399. # extruder.
  400. def _getSettingFromSupportInfillExtruder(self, setting_key, property = "value"):
  401. return self._getSettingFromExtruder(setting_key, "support_infill_extruder_nr", property)
  402. ## Helper function to get a setting from an extruder specified in another
  403. # setting.
  404. #
  405. # \param setting_key The key of the setting to get.
  406. # \param extruder_setting_key The key of the setting that specifies from
  407. # which extruder to get the setting, if there are multiple extruders.
  408. # \param property The property to get from the setting.
  409. # \return The property of the specified setting in the specified extruder.
  410. def _getSettingFromExtruder(self, setting_key, extruder_setting_key, property = "value"):
  411. multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
  412. if not multi_extrusion:
  413. return self._global_container_stack.getProperty(setting_key, property)
  414. extruder_index = self._global_container_stack.getProperty(extruder_setting_key, "value")
  415. if extruder_index == "-1": # If extruder index is -1 use global instead
  416. return self._global_container_stack.getProperty(setting_key, property)
  417. extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
  418. stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
  419. return stack.getProperty(setting_key, property)
  420. ## Convenience function to calculate the disallowed radius around the edge.
  421. #
  422. # This disallowed radius is to allow for space around the models that is
  423. # not part of the collision radius, such as bed adhesion (skirt/brim/raft)
  424. # and travel avoid distance.
  425. def _getEdgeDisallowedSize(self):
  426. if not self._global_container_stack:
  427. return 0
  428. container_stack = self._global_container_stack
  429. # If we are printing one at a time, we need to add the bed adhesion size to the disallowed areas of the objects
  430. if container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
  431. return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
  432. adhesion_type = container_stack.getProperty("adhesion_type", "value")
  433. if adhesion_type == "skirt":
  434. skirt_distance = self._getSettingFromAdhesionExtruder("skirt_gap")
  435. skirt_line_count = self._getSettingFromAdhesionExtruder("skirt_line_count")
  436. bed_adhesion_size = skirt_distance + (skirt_line_count * self._getSettingFromAdhesionExtruder("skirt_brim_line_width"))
  437. if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
  438. adhesion_extruder_nr = int(self._global_container_stack.getProperty("adhesion_extruder_nr", "value"))
  439. extruder_values = ExtruderManager.getInstance().getAllExtruderValues("skirt_brim_line_width")
  440. del extruder_values[adhesion_extruder_nr] # Remove the value of the adhesion extruder nr.
  441. for value in extruder_values:
  442. bed_adhesion_size += value
  443. elif adhesion_type == "brim":
  444. bed_adhesion_size = self._getSettingFromAdhesionExtruder("brim_line_count") * self._getSettingFromAdhesionExtruder("skirt_brim_line_width")
  445. if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
  446. adhesion_extruder_nr = int(self._global_container_stack.getProperty("adhesion_extruder_nr", "value"))
  447. extruder_values = ExtruderManager.getInstance().getAllExtruderValues("skirt_brim_line_width")
  448. del extruder_values[adhesion_extruder_nr] # Remove the value of the adhesion extruder nr.
  449. for value in extruder_values:
  450. bed_adhesion_size += value
  451. elif adhesion_type == "raft":
  452. bed_adhesion_size = self._getSettingFromAdhesionExtruder("raft_margin")
  453. else:
  454. raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
  455. support_expansion = 0
  456. if self._getSettingFromSupportInfillExtruder("support_offset"):
  457. support_expansion += self._getSettingFromSupportInfillExtruder("support_offset")
  458. farthest_shield_distance = 0
  459. if container_stack.getProperty("draft_shield_enabled", "value"):
  460. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("draft_shield_dist", "value"))
  461. if container_stack.getProperty("ooze_shield_enabled", "value"):
  462. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("ooze_shield_dist", "value"))
  463. move_from_wall_radius = 0 # Moves that start from outer wall.
  464. if self._getSettingFromAdhesionExtruder("infill_wipe_dist"):
  465. move_from_wall_radius = max(move_from_wall_radius, self._getSettingFromAdhesionExtruder("infill_wipe_dist"))
  466. if self._getSettingFromAdhesionExtruder("travel_avoid_distance"):
  467. move_from_wall_radius = max(move_from_wall_radius, self._getSettingFromAdhesionExtruder("travel_avoid_distance"))
  468. #Now combine our different pieces of data to get the final border size.
  469. #Support expansion is added to the bed adhesion, since the bed adhesion goes around support.
  470. #Support expansion is added to farthest shield distance, since the shields go around support.
  471. border_size = max(move_from_wall_radius, support_expansion + farthest_shield_distance, support_expansion + bed_adhesion_size)
  472. return border_size
  473. def _clamp(self, value, min_value, max_value):
  474. return max(min(value, max_value), min_value)
  475. _skirt_settings = ["adhesion_type", "skirt_gap", "skirt_line_count", "skirt_brim_line_width", "brim_width", "brim_line_count", "raft_margin", "draft_shield_enabled", "draft_shield_dist"]
  476. _raft_settings = ["adhesion_type", "raft_base_thickness", "raft_interface_thickness", "raft_surface_layers", "raft_surface_thickness", "raft_airgap"]
  477. _prime_settings = ["extruder_prime_pos_x", "extruder_prime_pos_y", "extruder_prime_pos_z"]
  478. _tower_settings = ["prime_tower_enable", "prime_tower_size", "prime_tower_position_x", "prime_tower_position_y"]
  479. _ooze_shield_settings = ["ooze_shield_enabled", "ooze_shield_dist"]
  480. _distance_settings = ["infill_wipe_dist", "travel_avoid_distance", "support_offset"]