BuildVolume.py 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  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. def _onSceneChanged(self, source):
  67. self._change_timer.start()
  68. def _onChangeTimerFinished(self):
  69. root = Application.getInstance().getController().getScene().getRoot()
  70. new_number_of_objects = len([node for node in BreadthFirstIterator(root) if node.getMeshData() and type(node) is SceneNode])
  71. if new_number_of_objects != self._number_of_objects:
  72. recalculate = False
  73. if self._global_container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
  74. recalculate = (new_number_of_objects < 2 and self._number_of_objects > 1) or (new_number_of_objects > 1 and self._number_of_objects < 2)
  75. self._number_of_objects = new_number_of_objects
  76. if recalculate:
  77. self._onSettingPropertyChanged("print_sequence", "value") # Create fake event, so right settings are triggered.
  78. def setWidth(self, width):
  79. if width: self._width = width
  80. def setHeight(self, height):
  81. if height: self._height = height
  82. def setDepth(self, depth):
  83. if depth: self._depth = depth
  84. def getDisallowedAreas(self):
  85. return self._disallowed_areas
  86. def setDisallowedAreas(self, areas):
  87. self._disallowed_areas = areas
  88. def render(self, renderer):
  89. if not self.getMeshData():
  90. return True
  91. if not self._shader:
  92. self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
  93. self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
  94. renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
  95. renderer.queueNode(self, mesh = self._grid_mesh, shader = self._grid_shader, backface_cull = True)
  96. if self._disallowed_area_mesh:
  97. renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
  98. if self._error_mesh:
  99. renderer.queueNode(self, mesh=self._error_mesh, shader=self._shader, transparent=True,
  100. backface_cull=True, sort=-8)
  101. return True
  102. ## Recalculates the build volume & disallowed areas.
  103. def rebuild(self):
  104. if not self._width or not self._height or not self._depth:
  105. return
  106. min_w = -self._width / 2
  107. max_w = self._width / 2
  108. min_h = 0.0
  109. max_h = self._height
  110. min_d = -self._depth / 2
  111. max_d = self._depth / 2
  112. mb = MeshBuilder()
  113. # Outline 'cube' of the build volume
  114. mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self.VolumeOutlineColor)
  115. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self.VolumeOutlineColor)
  116. mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
  117. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self.VolumeOutlineColor)
  118. mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
  119. mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
  120. mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  121. mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  122. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self.VolumeOutlineColor)
  123. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self.VolumeOutlineColor)
  124. mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self.VolumeOutlineColor)
  125. mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self.VolumeOutlineColor)
  126. self.setMeshData(mb.build())
  127. mb = MeshBuilder()
  128. mb.addQuad(
  129. Vector(min_w, min_h - 0.2, min_d),
  130. Vector(max_w, min_h - 0.2, min_d),
  131. Vector(max_w, min_h - 0.2, max_d),
  132. Vector(min_w, min_h - 0.2, max_d)
  133. )
  134. for n in range(0, 6):
  135. v = mb.getVertex(n)
  136. mb.setVertexUVCoordinates(n, v[0], v[2])
  137. self._grid_mesh = mb.build()
  138. disallowed_area_height = 0.1
  139. disallowed_area_size = 0
  140. if self._disallowed_areas:
  141. mb = MeshBuilder()
  142. color = Color(0.0, 0.0, 0.0, 0.15)
  143. for polygon in self._disallowed_areas:
  144. points = polygon.getPoints()
  145. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  146. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  147. for point in points:
  148. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d))
  149. mb.addFace(first, previous_point, new_point, color = color)
  150. previous_point = new_point
  151. # Find the largest disallowed area to exclude it from the maximum scale bounds.
  152. # This is a very nasty hack. This pretty much only works for UM machines.
  153. # This disallowed area_size needs a -lot- of rework at some point in the future: TODO
  154. 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.
  155. size = abs(numpy.max(points[:, 1]) - numpy.min(points[:, 1]))
  156. else:
  157. size = 0
  158. disallowed_area_size = max(size, disallowed_area_size)
  159. self._disallowed_area_mesh = mb.build()
  160. else:
  161. self._disallowed_area_mesh = None
  162. if self._error_areas:
  163. mb = MeshBuilder()
  164. for error_area in self._error_areas:
  165. color = Color(1.0, 0.0, 0.0, 0.5)
  166. points = error_area.getPoints()
  167. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  168. self._clamp(points[0][1], min_d, max_d))
  169. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  170. self._clamp(points[0][1], min_d, max_d))
  171. for point in points:
  172. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height,
  173. self._clamp(point[1], min_d, max_d))
  174. mb.addFace(first, previous_point, new_point, color=color)
  175. previous_point = new_point
  176. self._error_mesh = mb.build()
  177. else:
  178. self._error_mesh = None
  179. self._volume_aabb = AxisAlignedBox(
  180. minimum = Vector(min_w, min_h - 1.0, min_d),
  181. maximum = Vector(max_w, max_h - self._raft_thickness, max_d))
  182. bed_adhesion_size = self._getEdgeDisallowedSize()
  183. # As this works better for UM machines, we only add the disallowed_area_size for the z direction.
  184. # This is probably wrong in all other cases. TODO!
  185. # The +1 and -1 is added as there is always a bit of extra room required to work properly.
  186. scale_to_max_bounds = AxisAlignedBox(
  187. minimum = Vector(min_w + bed_adhesion_size + 1, min_h, min_d + disallowed_area_size - bed_adhesion_size + 1),
  188. maximum = Vector(max_w - bed_adhesion_size - 1, max_h - self._raft_thickness, max_d - disallowed_area_size + bed_adhesion_size - 1)
  189. )
  190. Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds
  191. def getBoundingBox(self):
  192. return self._volume_aabb
  193. def getRaftThickness(self):
  194. return self._raft_thickness
  195. def _updateRaftThickness(self):
  196. old_raft_thickness = self._raft_thickness
  197. self._adhesion_type = self._global_container_stack.getProperty("adhesion_type", "value")
  198. self._raft_thickness = 0.0
  199. if self._adhesion_type == "raft":
  200. self._raft_thickness = (
  201. self._global_container_stack.getProperty("raft_base_thickness", "value") +
  202. self._global_container_stack.getProperty("raft_interface_thickness", "value") +
  203. self._global_container_stack.getProperty("raft_surface_layers", "value") *
  204. self._global_container_stack.getProperty("raft_surface_thickness", "value") +
  205. self._global_container_stack.getProperty("raft_airgap", "value"))
  206. # Rounding errors do not matter, we check if raft_thickness has changed at all
  207. if old_raft_thickness != self._raft_thickness:
  208. self.setPosition(Vector(0, -self._raft_thickness, 0), SceneNode.TransformSpace.World)
  209. self.raftThicknessChanged.emit()
  210. ## Update the build volume visualization
  211. def _onStackChanged(self):
  212. if self._global_container_stack:
  213. self._global_container_stack.propertyChanged.disconnect(self._onSettingPropertyChanged)
  214. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  215. for extruder in extruders:
  216. extruder.propertyChanged.disconnect(self._onSettingPropertyChanged)
  217. self._global_container_stack = Application.getInstance().getGlobalContainerStack()
  218. if self._global_container_stack:
  219. self._global_container_stack.propertyChanged.connect(self._onSettingPropertyChanged)
  220. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  221. for extruder in extruders:
  222. extruder.propertyChanged.connect(self._onSettingPropertyChanged)
  223. self._width = self._global_container_stack.getProperty("machine_width", "value")
  224. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  225. if self._global_container_stack.getProperty("print_sequence", "value") == "one_at_a_time" and self._number_of_objects > 1:
  226. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  227. if self._height < machine_height:
  228. self._build_volume_message.show()
  229. else:
  230. self._build_volume_message.hide()
  231. else:
  232. self._height = self._global_container_stack.getProperty("machine_height", "value")
  233. self._build_volume_message.hide()
  234. self._depth = self._global_container_stack.getProperty("machine_depth", "value")
  235. self._updateDisallowedAreas()
  236. self._updateRaftThickness()
  237. self.rebuild()
  238. def _onSettingPropertyChanged(self, setting_key, property_name):
  239. if property_name != "value":
  240. return
  241. rebuild_me = False
  242. if setting_key == "print_sequence":
  243. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  244. if Application.getInstance().getGlobalContainerStack().getProperty("print_sequence", "value") == "one_at_a_time" and self._number_of_objects > 1:
  245. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  246. if self._height < machine_height:
  247. self._build_volume_message.show()
  248. else:
  249. self._build_volume_message.hide()
  250. else:
  251. self._height = self._global_container_stack.getProperty("machine_height", "value")
  252. self._build_volume_message.hide()
  253. rebuild_me = True
  254. 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:
  255. self._updateDisallowedAreas()
  256. rebuild_me = True
  257. if setting_key in self._raft_settings:
  258. self._updateRaftThickness()
  259. rebuild_me = True
  260. if rebuild_me:
  261. self.rebuild()
  262. def hasErrors(self):
  263. return self._has_errors
  264. def _updateDisallowedAreas(self):
  265. if not self._global_container_stack:
  266. return
  267. self._has_errors = False # Reset.
  268. self._error_areas = []
  269. disallowed_areas = copy.deepcopy(
  270. self._global_container_stack.getProperty("machine_disallowed_areas", "value"))
  271. areas = []
  272. machine_width = self._global_container_stack.getProperty("machine_width", "value")
  273. machine_depth = self._global_container_stack.getProperty("machine_depth", "value")
  274. prime_tower_area = None
  275. # Add prime tower location as disallowed area.
  276. if ExtruderManager.getInstance().getResolveOrValue("prime_tower_enable") == True:
  277. prime_tower_size = self._global_container_stack.getProperty("prime_tower_size", "value")
  278. prime_tower_x = self._global_container_stack.getProperty("prime_tower_position_x", "value") - machine_width / 2
  279. prime_tower_y = - self._global_container_stack.getProperty("prime_tower_position_y", "value") + machine_depth / 2
  280. prime_tower_area = Polygon([
  281. [prime_tower_x - prime_tower_size, prime_tower_y - prime_tower_size],
  282. [prime_tower_x, prime_tower_y - prime_tower_size],
  283. [prime_tower_x, prime_tower_y],
  284. [prime_tower_x - prime_tower_size, prime_tower_y],
  285. ])
  286. disallowed_polygons = []
  287. # Check if prime positions intersect with disallowed areas
  288. prime_collision = False
  289. if disallowed_areas:
  290. for area in disallowed_areas:
  291. poly = Polygon(numpy.array(area, numpy.float32))
  292. # Minkowski with zero, to ensure that the polygon is correct & watertight.
  293. poly = poly.getMinkowskiHull(Polygon.approximatedCircle(0))
  294. disallowed_polygons.append(poly)
  295. extruder_manager = ExtruderManager.getInstance()
  296. extruders = extruder_manager.getMachineExtruders(self._global_container_stack.getId())
  297. prime_polygons = []
  298. # Each extruder has it's own prime location
  299. for extruder in extruders:
  300. prime_x = extruder.getProperty("extruder_prime_pos_x", "value") - machine_width / 2
  301. prime_y = machine_depth / 2 - extruder.getProperty("extruder_prime_pos_y", "value")
  302. offset_x = extruder.getProperty("machine_nozzle_offset_x", "value")
  303. offset_y = extruder.getProperty("machine_nozzle_offset_y", "value")
  304. prime_x -= offset_x
  305. prime_y -= offset_y
  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. prime_tower_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. prime_tower_collision = True
  319. break
  320. if not prime_tower_collision:
  321. # Prime area is valid. Add as normal.
  322. # Once it's added like this, it will recieve a bed adhesion offset, just like the others.
  323. prime_polygons.append(prime_polygon)
  324. else:
  325. self._error_areas.append(prime_polygon)
  326. prime_collision = prime_collision or prime_tower_collision
  327. disallowed_polygons.extend(prime_polygons)
  328. disallowed_border_size = self._getEdgeDisallowedSize()
  329. # Extend every area already in the disallowed_areas with the skirt size.
  330. if disallowed_areas:
  331. for poly in disallowed_polygons:
  332. poly = poly.getMinkowskiHull(Polygon.approximatedCircle(disallowed_border_size))
  333. areas.append(poly)
  334. # Add the skirt areas around the borders of the build plate.
  335. if disallowed_border_size > 0:
  336. half_machine_width = self._global_container_stack.getProperty("machine_width", "value") / 2
  337. half_machine_depth = self._global_container_stack.getProperty("machine_depth", "value") / 2
  338. areas.append(Polygon(numpy.array([
  339. [-half_machine_width, -half_machine_depth],
  340. [-half_machine_width, half_machine_depth],
  341. [-half_machine_width + disallowed_border_size, half_machine_depth - disallowed_border_size],
  342. [-half_machine_width + disallowed_border_size, -half_machine_depth + disallowed_border_size]
  343. ], numpy.float32)))
  344. areas.append(Polygon(numpy.array([
  345. [half_machine_width, half_machine_depth],
  346. [half_machine_width, -half_machine_depth],
  347. [half_machine_width - disallowed_border_size, -half_machine_depth + disallowed_border_size],
  348. [half_machine_width - disallowed_border_size, half_machine_depth - disallowed_border_size]
  349. ], numpy.float32)))
  350. areas.append(Polygon(numpy.array([
  351. [-half_machine_width, half_machine_depth],
  352. [half_machine_width, half_machine_depth],
  353. [half_machine_width - disallowed_border_size, half_machine_depth - disallowed_border_size],
  354. [-half_machine_width + disallowed_border_size, half_machine_depth - disallowed_border_size]
  355. ], numpy.float32)))
  356. areas.append(Polygon(numpy.array([
  357. [half_machine_width, -half_machine_depth],
  358. [-half_machine_width, -half_machine_depth],
  359. [-half_machine_width + disallowed_border_size, -half_machine_depth + disallowed_border_size],
  360. [half_machine_width - disallowed_border_size, -half_machine_depth + disallowed_border_size]
  361. ], numpy.float32)))
  362. # Check if the prime tower area intersects with any of the other areas.
  363. # If this is the case, add it to the error area's so it can be drawn in red.
  364. # If not, add it back to disallowed area's, so it's rendered as normal.
  365. prime_tower_collision = False
  366. if prime_tower_area:
  367. # Using Minkowski of 0 fixes the prime tower area so it's rendered correctly
  368. prime_tower_area = prime_tower_area.getMinkowskiHull(Polygon.approximatedCircle(0))
  369. for area in areas:
  370. if prime_tower_area.intersectsPolygon(area) is not None:
  371. prime_tower_collision = True
  372. break
  373. if not prime_tower_collision:
  374. areas.append(prime_tower_area)
  375. else:
  376. self._error_areas.append(prime_tower_area)
  377. # The buildplate has errors if either prime tower or prime has a colission.
  378. self._has_errors = prime_tower_collision or prime_collision
  379. self._disallowed_areas = areas
  380. ## Private convenience function to get a setting from the adhesion extruder.
  381. def _getSettingProperty(self, setting_key, property = "value"):
  382. multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
  383. if not multi_extrusion:
  384. return self._global_container_stack.getProperty(setting_key, property)
  385. extruder_index = self._global_container_stack.getProperty("adhesion_extruder_nr", "value")
  386. if extruder_index == "-1": # If extruder index is -1 use global instead
  387. return self._global_container_stack.getProperty(setting_key, property)
  388. extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
  389. stack = UM.Settings.ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
  390. return stack.getProperty(setting_key, property)
  391. ## Convenience function to calculate the disallowed radius around the edge.
  392. #
  393. # This disallowed radius is to allow for space around the models that is
  394. # not part of the collision radius, such as bed adhesion (skirt/brim/raft)
  395. # and travel avoid distance.
  396. def _getEdgeDisallowedSize(self):
  397. if not self._global_container_stack:
  398. return 0
  399. container_stack = self._global_container_stack
  400. # If we are printing one at a time, we need to add the bed adhesion size to the disallowed areas of the objects
  401. if container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
  402. return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
  403. adhesion_type = container_stack.getProperty("adhesion_type", "value")
  404. if adhesion_type == "skirt":
  405. skirt_distance = self._getSettingProperty("skirt_gap", "value")
  406. skirt_line_count = self._getSettingProperty("skirt_line_count", "value")
  407. bed_adhesion_size = skirt_distance + (skirt_line_count * self._getSettingProperty("skirt_brim_line_width", "value"))
  408. if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
  409. adhesion_extruder_nr = int(self._global_container_stack.getProperty("adhesion_extruder_nr", "value"))
  410. extruder_values = ExtruderManager.getInstance().getAllExtruderValues("skirt_brim_line_width")
  411. del extruder_values[adhesion_extruder_nr] # Remove the value of the adhesion extruder nr.
  412. for value in extruder_values:
  413. bed_adhesion_size += value
  414. elif adhesion_type == "brim":
  415. bed_adhesion_size = self._getSettingProperty("brim_line_count", "value") * self._getSettingProperty("skirt_brim_line_width", "value")
  416. if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
  417. adhesion_extruder_nr = int(self._global_container_stack.getProperty("adhesion_extruder_nr", "value"))
  418. extruder_values = ExtruderManager.getInstance().getAllExtruderValues("skirt_brim_line_width")
  419. del extruder_values[adhesion_extruder_nr] # Remove the value of the adhesion extruder nr.
  420. for value in extruder_values:
  421. bed_adhesion_size += value
  422. elif adhesion_type == "raft":
  423. bed_adhesion_size = self._getSettingProperty("raft_margin", "value")
  424. else:
  425. raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
  426. farthest_shield_distance = 0
  427. if container_stack.getProperty("draft_shield_enabled", "value"):
  428. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("draft_shield_dist", "value"))
  429. if container_stack.getProperty("ooze_shield_enabled", "value"):
  430. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("ooze_shield_dist", "value"))
  431. move_from_wall_radius = 0 # Moves that start from outer wall.
  432. if self._getSettingProperty("infill_wipe_dist", "value"):
  433. move_from_wall_radius = max(move_from_wall_radius, self._getSettingProperty("infill_wipe_dist", "value"))
  434. if self._getSettingProperty("travel_avoid_distance", "value"):
  435. move_from_wall_radius = max(move_from_wall_radius, self._getSettingProperty("travel_avoid_distance", "value"))
  436. #Now combine our different pieces of data to get the final border size.
  437. border_size = max(farthest_shield_distance, move_from_wall_radius, bed_adhesion_size)
  438. return border_size
  439. def _clamp(self, value, min_value, max_value):
  440. return max(min(value, max_value), min_value)
  441. _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"]
  442. _raft_settings = ["adhesion_type", "raft_base_thickness", "raft_interface_thickness", "raft_surface_layers", "raft_surface_thickness", "raft_airgap"]
  443. _prime_settings = ["extruder_prime_pos_x", "extruder_prime_pos_y", "extruder_prime_pos_z"]
  444. _tower_settings = ["prime_tower_enable", "prime_tower_size", "prime_tower_position_x", "prime_tower_position_y"]
  445. _ooze_shield_settings = ["ooze_shield_enabled", "ooze_shield_dist"]
  446. _distance_settings = ["infill_wipe_dist", "travel_avoid_distance"]