BuildVolume.py 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016
  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.Settings.ContainerRegistry import ContainerRegistry
  5. from UM.i18n import i18nCatalog
  6. from UM.Scene.Platform import Platform
  7. from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator
  8. from UM.Scene.SceneNode import SceneNode
  9. from UM.Application import Application
  10. from UM.Resources import Resources
  11. from UM.Mesh.MeshBuilder import MeshBuilder
  12. from UM.Math.Vector import Vector
  13. from UM.Math.Matrix import Matrix
  14. from UM.Math.Color import Color
  15. from UM.Math.AxisAlignedBox import AxisAlignedBox
  16. from UM.Math.Polygon import Polygon
  17. from UM.Message import Message
  18. from UM.Signal import Signal
  19. from PyQt5.QtCore import QTimer
  20. from UM.View.RenderBatch import RenderBatch
  21. from UM.View.GL.OpenGL import OpenGL
  22. catalog = i18nCatalog("cura")
  23. import numpy
  24. import math
  25. from typing import List
  26. # Setting for clearance around the prime
  27. PRIME_CLEARANCE = 6.5
  28. ## Build volume is a special kind of node that is responsible for rendering the printable area & disallowed areas.
  29. class BuildVolume(SceneNode):
  30. raftThicknessChanged = Signal()
  31. def __init__(self, parent = None):
  32. super().__init__(parent)
  33. self._volume_outline_color = None
  34. self._x_axis_color = None
  35. self._y_axis_color = None
  36. self._z_axis_color = None
  37. self._disallowed_area_color = None
  38. self._error_area_color = None
  39. self._grid_color = None
  40. self._grid_minor_color = None
  41. self._width = 0
  42. self._height = 0
  43. self._depth = 0
  44. self._shape = ""
  45. self._shader = None
  46. self._origin_mesh = None
  47. self._origin_line_length = 20
  48. self._origin_line_width = 0.5
  49. self._plate_mesh = None
  50. self._grid_mesh = None
  51. self._grid_shader = None
  52. self._disallowed_areas = []
  53. self._disallowed_area_mesh = None
  54. self._error_areas = []
  55. self._error_mesh = None
  56. self.setCalculateBoundingBox(False)
  57. self._volume_aabb = None
  58. self._raft_thickness = 0.0
  59. self._extra_z_clearance = 0.0
  60. self._adhesion_type = None
  61. self._platform = Platform(self)
  62. self._global_container_stack = None
  63. Application.getInstance().globalContainerStackChanged.connect(self._onStackChanged)
  64. self._onStackChanged()
  65. self._engine_ready = False
  66. Application.getInstance().engineCreatedSignal.connect(self._onEngineCreated)
  67. self._has_errors = False
  68. Application.getInstance().getController().getScene().sceneChanged.connect(self._onSceneChanged)
  69. #Objects loaded at the moment. We are connected to the property changed events of these objects.
  70. self._scene_objects = set()
  71. self._change_timer = QTimer()
  72. self._change_timer.setInterval(100)
  73. self._change_timer.setSingleShot(True)
  74. self._change_timer.timeout.connect(self._onChangeTimerFinished)
  75. self._build_volume_message = Message(catalog.i18nc("@info:status",
  76. "The build volume height has been reduced due to the value of the"
  77. " \"Print Sequence\" setting to prevent the gantry from colliding"
  78. " with printed models."))
  79. # Must be after setting _build_volume_message, apparently that is used in getMachineManager.
  80. # activeQualityChanged is always emitted after setActiveVariant, setActiveMaterial and setActiveQuality.
  81. # Therefore this works.
  82. Application.getInstance().getMachineManager().activeQualityChanged.connect(self._onStackChanged)
  83. # This should also ways work, and it is semantically more correct,
  84. # but it does not update the disallowed areas after material change
  85. Application.getInstance().getMachineManager().activeStackChanged.connect(self._onStackChanged)
  86. def _onSceneChanged(self, source):
  87. if self._global_container_stack:
  88. self._change_timer.start()
  89. def _onChangeTimerFinished(self):
  90. root = Application.getInstance().getController().getScene().getRoot()
  91. new_scene_objects = set(node for node in BreadthFirstIterator(root) if node.callDecoration("isSliceable"))
  92. if new_scene_objects != self._scene_objects:
  93. for node in new_scene_objects - self._scene_objects: #Nodes that were added to the scene.
  94. self._updateNodeListeners(node)
  95. node.decoratorsChanged.connect(self._updateNodeListeners) # Make sure that decoration changes afterwards also receive the same treatment
  96. for node in self._scene_objects - new_scene_objects: #Nodes that were removed from the scene.
  97. per_mesh_stack = node.callDecoration("getStack")
  98. if per_mesh_stack:
  99. per_mesh_stack.propertyChanged.disconnect(self._onSettingPropertyChanged)
  100. active_extruder_changed = node.callDecoration("getActiveExtruderChangedSignal")
  101. if active_extruder_changed is not None:
  102. node.callDecoration("getActiveExtruderChangedSignal").disconnect(self._updateDisallowedAreasAndRebuild)
  103. node.decoratorsChanged.disconnect(self._updateNodeListeners)
  104. self._scene_objects = new_scene_objects
  105. self._onSettingPropertyChanged("print_sequence", "value") # Create fake event, so right settings are triggered.
  106. ## Updates the listeners that listen for changes in per-mesh stacks.
  107. #
  108. # \param node The node for which the decorators changed.
  109. def _updateNodeListeners(self, node: SceneNode):
  110. per_mesh_stack = node.callDecoration("getStack")
  111. if per_mesh_stack:
  112. per_mesh_stack.propertyChanged.connect(self._onSettingPropertyChanged)
  113. active_extruder_changed = node.callDecoration("getActiveExtruderChangedSignal")
  114. if active_extruder_changed is not None:
  115. active_extruder_changed.connect(self._updateDisallowedAreasAndRebuild)
  116. self._updateDisallowedAreasAndRebuild()
  117. def setWidth(self, width):
  118. if width is not None:
  119. self._width = width
  120. def setHeight(self, height):
  121. if height is not None:
  122. self._height = height
  123. def setDepth(self, depth):
  124. if depth is not None:
  125. self._depth = depth
  126. def setShape(self, shape: str):
  127. if shape:
  128. self._shape = shape
  129. def getDisallowedAreas(self) -> List[Polygon]:
  130. return self._disallowed_areas
  131. def setDisallowedAreas(self, areas: List[Polygon]):
  132. self._disallowed_areas = areas
  133. def render(self, renderer):
  134. if not self.getMeshData():
  135. return True
  136. if not self._shader:
  137. self._shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "default.shader"))
  138. self._grid_shader = OpenGL.getInstance().createShaderProgram(Resources.getPath(Resources.Shaders, "grid.shader"))
  139. theme = Application.getInstance().getTheme()
  140. self._grid_shader.setUniformValue("u_buildplateColor", Color(*theme.getColor("buildplate").getRgb()))
  141. renderer.queueNode(self, mode = RenderBatch.RenderMode.Lines)
  142. renderer.queueNode(self, mesh = self._origin_mesh)
  143. renderer.queueNode(self, mesh = self._plate_mesh, shader = self._grid_shader, backface_cull = True)
  144. renderer.queueNode(self, mesh = self._grid_mesh, mode = RenderBatch.RenderMode.Lines)
  145. if self._disallowed_area_mesh:
  146. renderer.queueNode(self, mesh = self._disallowed_area_mesh, shader = self._shader, transparent = True, backface_cull = True, sort = -9)
  147. if self._error_mesh:
  148. renderer.queueNode(self, mesh=self._error_mesh, shader=self._shader, transparent=True,
  149. backface_cull=True, sort=-8)
  150. return True
  151. ## For every sliceable node, update node._outside_buildarea
  152. #
  153. def updateNodeBoundaryCheck(self):
  154. root = Application.getInstance().getController().getScene().getRoot()
  155. nodes = list(BreadthFirstIterator(root))
  156. group_nodes = []
  157. build_volume_bounding_box = self.getBoundingBox()
  158. if build_volume_bounding_box:
  159. # It's over 9000!
  160. build_volume_bounding_box = build_volume_bounding_box.set(bottom=-9001)
  161. else:
  162. # No bounding box. This is triggered when running Cura from command line with a model for the first time
  163. # In that situation there is a model, but no machine (and therefore no build volume.
  164. return
  165. for node in nodes:
  166. # Need to check group nodes later
  167. if node.callDecoration("isGroup"):
  168. group_nodes.append(node) # Keep list of affected group_nodes
  169. if node.callDecoration("isSliceable") or node.callDecoration("isGroup"):
  170. node._outside_buildarea = False
  171. bbox = node.getBoundingBox()
  172. # Mark the node as outside the build volume if the bounding box test fails.
  173. if build_volume_bounding_box.intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection:
  174. node._outside_buildarea = True
  175. continue
  176. convex_hull = node.callDecoration("getConvexHull")
  177. if convex_hull:
  178. if not convex_hull.isValid():
  179. return
  180. # Check for collisions between disallowed areas and the object
  181. for area in self.getDisallowedAreas():
  182. overlap = convex_hull.intersectsPolygon(area)
  183. if overlap is None:
  184. continue
  185. node._outside_buildarea = True
  186. continue
  187. # Group nodes should override the _outside_buildarea property of their children.
  188. for group_node in group_nodes:
  189. for child_node in group_node.getAllChildren():
  190. child_node._outside_buildarea = group_node._outside_buildarea
  191. ## Recalculates the build volume & disallowed areas.
  192. def rebuild(self):
  193. if not self._width or not self._height or not self._depth:
  194. return
  195. if not Application.getInstance()._engine:
  196. return
  197. if not self._volume_outline_color:
  198. theme = Application.getInstance().getTheme()
  199. self._volume_outline_color = Color(*theme.getColor("volume_outline").getRgb())
  200. self._x_axis_color = Color(*theme.getColor("x_axis").getRgb())
  201. self._y_axis_color = Color(*theme.getColor("y_axis").getRgb())
  202. self._z_axis_color = Color(*theme.getColor("z_axis").getRgb())
  203. self._disallowed_area_color = Color(*theme.getColor("disallowed_area").getRgb())
  204. self._error_area_color = Color(*theme.getColor("error_area").getRgb())
  205. self._grid_color = Color(*theme.getColor("buildplate_grid").getRgb())
  206. self._grid_minor_color = Color(*theme.getColor("buildplate_grid_minor").getRgb())
  207. min_w = -self._width / 2
  208. max_w = self._width / 2
  209. min_h = 0.0
  210. max_h = self._height
  211. min_d = -self._depth / 2
  212. max_d = self._depth / 2
  213. z_fight_distance = 0.2 # Distance between buildplate and disallowed area meshes to prevent z-fighting
  214. if self._shape != "elliptic":
  215. # Outline 'cube' of the build volume
  216. mb = MeshBuilder()
  217. mb.addLine(Vector(min_w, min_h, min_d), Vector(max_w, min_h, min_d), color = self._volume_outline_color)
  218. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, max_h, min_d), color = self._volume_outline_color)
  219. mb.addLine(Vector(min_w, max_h, min_d), Vector(max_w, max_h, min_d), color = self._volume_outline_color)
  220. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, max_h, min_d), color = self._volume_outline_color)
  221. mb.addLine(Vector(min_w, min_h, max_d), Vector(max_w, min_h, max_d), color = self._volume_outline_color)
  222. mb.addLine(Vector(min_w, min_h, max_d), Vector(min_w, max_h, max_d), color = self._volume_outline_color)
  223. mb.addLine(Vector(min_w, max_h, max_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)
  224. mb.addLine(Vector(max_w, min_h, max_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)
  225. mb.addLine(Vector(min_w, min_h, min_d), Vector(min_w, min_h, max_d), color = self._volume_outline_color)
  226. mb.addLine(Vector(max_w, min_h, min_d), Vector(max_w, min_h, max_d), color = self._volume_outline_color)
  227. mb.addLine(Vector(min_w, max_h, min_d), Vector(min_w, max_h, max_d), color = self._volume_outline_color)
  228. mb.addLine(Vector(max_w, max_h, min_d), Vector(max_w, max_h, max_d), color = self._volume_outline_color)
  229. self.setMeshData(mb.build())
  230. # Build plate surface.
  231. mb = MeshBuilder()
  232. mb.addQuad(
  233. Vector(min_w, min_h - z_fight_distance, min_d),
  234. Vector(max_w, min_h - z_fight_distance, min_d),
  235. Vector(max_w, min_h - z_fight_distance, max_d),
  236. Vector(min_w, min_h - z_fight_distance, max_d)
  237. )
  238. for n in range(0, 6):
  239. v = mb.getVertex(n)
  240. mb.setVertexUVCoordinates(n, v[0], v[2])
  241. self._plate_mesh = mb.build()
  242. #Build plate grid mesh.
  243. major_grid_size = 10 #In millimetres.
  244. mb = MeshBuilder()
  245. for x in range(0, int(math.ceil(max_w)), major_grid_size):
  246. mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color)
  247. for x in range(0, int(math.floor(min_w)), -major_grid_size): #Start from 0 in both cases, so you need to do this in two for loops.
  248. mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_color)
  249. for y in range(0, int(math.ceil(max_d)), major_grid_size):
  250. mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color)
  251. for y in range(0, int(math.floor(min_d)), -major_grid_size):
  252. mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_color)
  253. minor_grid_size = 1
  254. for x in range(0, int(math.ceil(max_w)), minor_grid_size):
  255. if x % major_grid_size == 0: #Don't overlap with the major grid.
  256. pass
  257. mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color)
  258. for x in range(0, int(math.floor(min_w)), -minor_grid_size):
  259. if x % major_grid_size == 0:
  260. pass
  261. mb.addLine(Vector(x, min_h, min_d), Vector(x, min_h, max_d), color = self._grid_minor_color)
  262. for y in range(0, int(math.ceil(max_d)), minor_grid_size):
  263. if y % major_grid_size == 0:
  264. pass
  265. mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color)
  266. for y in range(0, int(math.floor(min_d)), -minor_grid_size):
  267. if y % major_grid_size == 0:
  268. pass
  269. mb.addLine(Vector(min_w, min_h, y), Vector(max_w, min_h, y), color = self._grid_minor_color)
  270. self._grid_mesh = mb.build()
  271. else:
  272. # Bottom and top 'ellipse' of the build volume
  273. aspect = 1.0
  274. scale_matrix = Matrix()
  275. if self._width != 0:
  276. # Scale circular meshes by aspect ratio if width != height
  277. aspect = self._depth / self._width
  278. scale_matrix.compose(scale = Vector(1, 1, aspect))
  279. mb = MeshBuilder()
  280. mb.addArc(max_w, Vector.Unit_Y, center = (0, min_h - z_fight_distance, 0), color = self._volume_outline_color)
  281. mb.addArc(max_w, Vector.Unit_Y, center = (0, max_h, 0), color = self._volume_outline_color)
  282. self.setMeshData(mb.build().getTransformed(scale_matrix))
  283. # Build plate grid mesh
  284. mb = MeshBuilder()
  285. mb.addVertex(0, min_h - z_fight_distance, 0)
  286. mb.addArc(max_w, Vector.Unit_Y, center = Vector(0, min_h - z_fight_distance, 0))
  287. sections = mb.getVertexCount() - 1 # Center point is not an arc section
  288. indices = []
  289. for n in range(0, sections - 1):
  290. indices.append([0, n + 2, n + 1])
  291. mb.addIndices(numpy.asarray(indices, dtype = numpy.int32))
  292. mb.calculateNormals()
  293. for n in range(0, mb.getVertexCount()):
  294. v = mb.getVertex(n)
  295. mb.setVertexUVCoordinates(n, v[0], v[2] * aspect)
  296. self._grid_mesh = mb.build().getTransformed(scale_matrix)
  297. # Indication of the machine origin
  298. if self._global_container_stack.getProperty("machine_center_is_zero", "value"):
  299. origin = (Vector(min_w, min_h, min_d) + Vector(max_w, min_h, max_d)) / 2
  300. else:
  301. origin = Vector(min_w, min_h, max_d)
  302. mb = MeshBuilder()
  303. mb.addCube(
  304. width = self._origin_line_length,
  305. height = self._origin_line_width,
  306. depth = self._origin_line_width,
  307. center = origin + Vector(self._origin_line_length / 2, 0, 0),
  308. color = self._x_axis_color
  309. )
  310. mb.addCube(
  311. width = self._origin_line_width,
  312. height = self._origin_line_length,
  313. depth = self._origin_line_width,
  314. center = origin + Vector(0, self._origin_line_length / 2, 0),
  315. color = self._y_axis_color
  316. )
  317. mb.addCube(
  318. width = self._origin_line_width,
  319. height = self._origin_line_width,
  320. depth = self._origin_line_length,
  321. center = origin - Vector(0, 0, self._origin_line_length / 2),
  322. color = self._z_axis_color
  323. )
  324. self._origin_mesh = mb.build()
  325. disallowed_area_height = 0.1
  326. disallowed_area_size = 0
  327. if self._disallowed_areas:
  328. mb = MeshBuilder()
  329. color = self._disallowed_area_color
  330. for polygon in self._disallowed_areas:
  331. points = polygon.getPoints()
  332. if len(points) == 0:
  333. continue
  334. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  335. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height, self._clamp(points[0][1], min_d, max_d))
  336. for point in points:
  337. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height, self._clamp(point[1], min_d, max_d))
  338. mb.addFace(first, previous_point, new_point, color = color)
  339. previous_point = new_point
  340. # Find the largest disallowed area to exclude it from the maximum scale bounds.
  341. # This is a very nasty hack. This pretty much only works for UM machines.
  342. # This disallowed area_size needs a -lot- of rework at some point in the future: TODO
  343. 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.
  344. size = abs(numpy.max(points[:, 1]) - numpy.min(points[:, 1]))
  345. else:
  346. size = 0
  347. disallowed_area_size = max(size, disallowed_area_size)
  348. self._disallowed_area_mesh = mb.build()
  349. else:
  350. self._disallowed_area_mesh = None
  351. if self._error_areas:
  352. mb = MeshBuilder()
  353. for error_area in self._error_areas:
  354. color = self._error_area_color
  355. points = error_area.getPoints()
  356. first = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  357. self._clamp(points[0][1], min_d, max_d))
  358. previous_point = Vector(self._clamp(points[0][0], min_w, max_w), disallowed_area_height,
  359. self._clamp(points[0][1], min_d, max_d))
  360. for point in points:
  361. new_point = Vector(self._clamp(point[0], min_w, max_w), disallowed_area_height,
  362. self._clamp(point[1], min_d, max_d))
  363. mb.addFace(first, previous_point, new_point, color=color)
  364. previous_point = new_point
  365. self._error_mesh = mb.build()
  366. else:
  367. self._error_mesh = None
  368. self._volume_aabb = AxisAlignedBox(
  369. minimum = Vector(min_w, min_h - 1.0, min_d),
  370. maximum = Vector(max_w, max_h - self._raft_thickness - self._extra_z_clearance, max_d))
  371. bed_adhesion_size = self._getEdgeDisallowedSize()
  372. # As this works better for UM machines, we only add the disallowed_area_size for the z direction.
  373. # This is probably wrong in all other cases. TODO!
  374. # The +1 and -1 is added as there is always a bit of extra room required to work properly.
  375. scale_to_max_bounds = AxisAlignedBox(
  376. minimum = Vector(min_w + bed_adhesion_size + 1, min_h, min_d + disallowed_area_size - bed_adhesion_size + 1),
  377. maximum = Vector(max_w - bed_adhesion_size - 1, max_h - self._raft_thickness - self._extra_z_clearance, max_d - disallowed_area_size + bed_adhesion_size - 1)
  378. )
  379. Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds
  380. self.updateNodeBoundaryCheck()
  381. def getBoundingBox(self) -> AxisAlignedBox:
  382. return self._volume_aabb
  383. def getRaftThickness(self) -> float:
  384. return self._raft_thickness
  385. def _updateRaftThickness(self):
  386. old_raft_thickness = self._raft_thickness
  387. self._adhesion_type = self._global_container_stack.getProperty("adhesion_type", "value")
  388. self._raft_thickness = 0.0
  389. if self._adhesion_type == "raft":
  390. self._raft_thickness = (
  391. self._global_container_stack.getProperty("raft_base_thickness", "value") +
  392. self._global_container_stack.getProperty("raft_interface_thickness", "value") +
  393. self._global_container_stack.getProperty("raft_surface_layers", "value") *
  394. self._global_container_stack.getProperty("raft_surface_thickness", "value") +
  395. self._global_container_stack.getProperty("raft_airgap", "value") -
  396. self._global_container_stack.getProperty("layer_0_z_overlap", "value"))
  397. # Rounding errors do not matter, we check if raft_thickness has changed at all
  398. if old_raft_thickness != self._raft_thickness:
  399. self.setPosition(Vector(0, -self._raft_thickness, 0), SceneNode.TransformSpace.World)
  400. self.raftThicknessChanged.emit()
  401. def _updateExtraZClearance(self) -> None:
  402. extra_z = 0.0
  403. extruders = ExtruderManager.getInstance().getUsedExtruderStacks()
  404. use_extruders = False
  405. for extruder in extruders:
  406. if extruder.getProperty("retraction_hop_enabled", "value"):
  407. retraction_hop = extruder.getProperty("retraction_hop", "value")
  408. if extra_z is None or retraction_hop > extra_z:
  409. extra_z = retraction_hop
  410. use_extruders = True
  411. if not use_extruders:
  412. # If no extruders, take global value.
  413. if self._global_container_stack.getProperty("retraction_hop_enabled", "value"):
  414. extra_z = self._global_container_stack.getProperty("retraction_hop", "value")
  415. if extra_z != self._extra_z_clearance:
  416. self._extra_z_clearance = extra_z
  417. ## Update the build volume visualization
  418. def _onStackChanged(self):
  419. if self._global_container_stack:
  420. self._global_container_stack.propertyChanged.disconnect(self._onSettingPropertyChanged)
  421. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  422. for extruder in extruders:
  423. extruder.propertyChanged.disconnect(self._onSettingPropertyChanged)
  424. self._global_container_stack = Application.getInstance().getGlobalContainerStack()
  425. if self._global_container_stack:
  426. self._global_container_stack.propertyChanged.connect(self._onSettingPropertyChanged)
  427. extruders = ExtruderManager.getInstance().getMachineExtruders(self._global_container_stack.getId())
  428. for extruder in extruders:
  429. extruder.propertyChanged.connect(self._onSettingPropertyChanged)
  430. self._width = self._global_container_stack.getProperty("machine_width", "value")
  431. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  432. if self._global_container_stack.getProperty("print_sequence", "value") == "one_at_a_time" and len(self._scene_objects) > 1:
  433. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  434. if self._height < machine_height:
  435. self._build_volume_message.show()
  436. else:
  437. self._build_volume_message.hide()
  438. else:
  439. self._height = self._global_container_stack.getProperty("machine_height", "value")
  440. self._build_volume_message.hide()
  441. self._depth = self._global_container_stack.getProperty("machine_depth", "value")
  442. self._shape = self._global_container_stack.getProperty("machine_shape", "value")
  443. self._updateDisallowedAreas()
  444. self._updateRaftThickness()
  445. self._updateExtraZClearance()
  446. if self._engine_ready:
  447. self.rebuild()
  448. def _onEngineCreated(self):
  449. self._engine_ready = True
  450. self.rebuild()
  451. def _onSettingPropertyChanged(self, setting_key: str, property_name: str):
  452. if property_name != "value":
  453. return
  454. rebuild_me = False
  455. if setting_key == "print_sequence":
  456. machine_height = self._global_container_stack.getProperty("machine_height", "value")
  457. if Application.getInstance().getGlobalContainerStack().getProperty("print_sequence", "value") == "one_at_a_time" and len(self._scene_objects) > 1:
  458. self._height = min(self._global_container_stack.getProperty("gantry_height", "value"), machine_height)
  459. if self._height < machine_height:
  460. self._build_volume_message.show()
  461. else:
  462. self._build_volume_message.hide()
  463. else:
  464. self._height = self._global_container_stack.getProperty("machine_height", "value")
  465. self._build_volume_message.hide()
  466. rebuild_me = True
  467. 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 or setting_key in self._extruder_settings:
  468. self._updateDisallowedAreas()
  469. rebuild_me = True
  470. if setting_key in self._raft_settings:
  471. self._updateRaftThickness()
  472. rebuild_me = True
  473. if setting_key in self._extra_z_settings:
  474. self._updateExtraZClearance()
  475. rebuild_me = True
  476. if setting_key in self._limit_to_extruder_settings:
  477. self._updateDisallowedAreas()
  478. rebuild_me = True
  479. if rebuild_me:
  480. self.rebuild()
  481. def hasErrors(self) -> bool:
  482. return self._has_errors
  483. ## Calls _updateDisallowedAreas and makes sure the changes appear in the
  484. # scene.
  485. #
  486. # This is required for a signal to trigger the update in one go. The
  487. # ``_updateDisallowedAreas`` method itself shouldn't call ``rebuild``,
  488. # since there may be other changes before it needs to be rebuilt, which
  489. # would hit performance.
  490. def _updateDisallowedAreasAndRebuild(self):
  491. self._updateDisallowedAreas()
  492. self._updateRaftThickness()
  493. self._updateExtraZClearance()
  494. self.rebuild()
  495. def _updateDisallowedAreas(self):
  496. if not self._global_container_stack:
  497. return
  498. self._error_areas = []
  499. extruder_manager = ExtruderManager.getInstance()
  500. used_extruders = extruder_manager.getUsedExtruderStacks()
  501. disallowed_border_size = self._getEdgeDisallowedSize()
  502. if not used_extruders:
  503. # If no extruder is used, assume that the active extruder is used (else nothing is drawn)
  504. if extruder_manager.getActiveExtruderStack():
  505. used_extruders = [extruder_manager.getActiveExtruderStack()]
  506. else:
  507. used_extruders = [self._global_container_stack]
  508. result_areas = self._computeDisallowedAreasStatic(disallowed_border_size, used_extruders) #Normal machine disallowed areas can always be added.
  509. prime_areas = self._computeDisallowedAreasPrimeBlob(disallowed_border_size, used_extruders)
  510. prime_disallowed_areas = self._computeDisallowedAreasStatic(0, used_extruders) #Where the priming is not allowed to happen. This is not added to the result, just for collision checking.
  511. #Check if prime positions intersect with disallowed areas.
  512. for extruder in used_extruders:
  513. extruder_id = extruder.getId()
  514. collision = False
  515. for prime_polygon in prime_areas[extruder_id]:
  516. for disallowed_polygon in prime_disallowed_areas[extruder_id]:
  517. if prime_polygon.intersectsPolygon(disallowed_polygon) is not None:
  518. collision = True
  519. break
  520. if collision:
  521. break
  522. #Also check other prime positions (without additional offset).
  523. for other_extruder_id in prime_areas:
  524. if extruder_id == other_extruder_id: #It is allowed to collide with itself.
  525. continue
  526. for other_prime_polygon in prime_areas[other_extruder_id]:
  527. if prime_polygon.intersectsPolygon(other_prime_polygon):
  528. collision = True
  529. break
  530. if collision:
  531. break
  532. if collision:
  533. break
  534. result_areas[extruder_id].extend(prime_areas[extruder_id])
  535. nozzle_disallowed_areas = extruder.getProperty("nozzle_disallowed_areas", "value")
  536. for area in nozzle_disallowed_areas:
  537. polygon = Polygon(numpy.array(area, numpy.float32))
  538. polygon = polygon.getMinkowskiHull(Polygon.approximatedCircle(disallowed_border_size))
  539. result_areas[extruder_id].append(polygon) #Don't perform the offset on these.
  540. # Add prime tower location as disallowed area.
  541. if len(used_extruders) > 1: #No prime tower in single-extrusion.
  542. prime_tower_collision = False
  543. prime_tower_areas = self._computeDisallowedAreasPrinted(used_extruders)
  544. for extruder_id in prime_tower_areas:
  545. for prime_tower_area in prime_tower_areas[extruder_id]:
  546. for area in result_areas[extruder_id]:
  547. if prime_tower_area.intersectsPolygon(area) is not None:
  548. prime_tower_collision = True
  549. break
  550. if prime_tower_collision: #Already found a collision.
  551. break
  552. if not prime_tower_collision:
  553. result_areas[extruder_id].extend(prime_tower_areas[extruder_id])
  554. else:
  555. self._error_areas.extend(prime_tower_areas[extruder_id])
  556. self._has_errors = len(self._error_areas) > 0
  557. self._disallowed_areas = []
  558. for extruder_id in result_areas:
  559. self._disallowed_areas.extend(result_areas[extruder_id])
  560. ## Computes the disallowed areas for objects that are printed with print
  561. # features.
  562. #
  563. # This means that the brim, travel avoidance and such will be applied to
  564. # these features.
  565. #
  566. # \return A dictionary with for each used extruder ID the disallowed areas
  567. # where that extruder may not print.
  568. def _computeDisallowedAreasPrinted(self, used_extruders):
  569. result = {}
  570. for extruder in used_extruders:
  571. result[extruder.getId()] = []
  572. #Currently, the only normally printed object is the prime tower.
  573. if ExtruderManager.getInstance().getResolveOrValue("prime_tower_enable"):
  574. prime_tower_size = self._global_container_stack.getProperty("prime_tower_size", "value")
  575. machine_width = self._global_container_stack.getProperty("machine_width", "value")
  576. machine_depth = self._global_container_stack.getProperty("machine_depth", "value")
  577. prime_tower_x = self._global_container_stack.getProperty("prime_tower_position_x", "value")
  578. prime_tower_y = - self._global_container_stack.getProperty("prime_tower_position_y", "value")
  579. if not self._global_container_stack.getProperty("machine_center_is_zero", "value"):
  580. prime_tower_x = prime_tower_x - machine_width / 2 #Offset by half machine_width and _depth to put the origin in the front-left.
  581. prime_tower_y = prime_tower_y + machine_depth / 2
  582. prime_tower_area = Polygon([
  583. [prime_tower_x - prime_tower_size, prime_tower_y - prime_tower_size],
  584. [prime_tower_x, prime_tower_y - prime_tower_size],
  585. [prime_tower_x, prime_tower_y],
  586. [prime_tower_x - prime_tower_size, prime_tower_y],
  587. ])
  588. prime_tower_area = prime_tower_area.getMinkowskiHull(Polygon.approximatedCircle(0))
  589. for extruder in used_extruders:
  590. result[extruder.getId()].append(prime_tower_area) #The prime tower location is the same for each extruder, regardless of offset.
  591. return result
  592. ## Computes the disallowed areas for the prime blobs.
  593. #
  594. # These are special because they are not subject to things like brim or
  595. # travel avoidance. They do get a dilute with the border size though
  596. # because they may not intersect with brims and such of other objects.
  597. #
  598. # \param border_size The size with which to offset the disallowed areas
  599. # due to skirt, brim, travel avoid distance, etc.
  600. # \param used_extruders The extruder stacks to generate disallowed areas
  601. # for.
  602. # \return A dictionary with for each used extruder ID the prime areas.
  603. def _computeDisallowedAreasPrimeBlob(self, border_size, used_extruders):
  604. result = {}
  605. machine_width = self._global_container_stack.getProperty("machine_width", "value")
  606. machine_depth = self._global_container_stack.getProperty("machine_depth", "value")
  607. for extruder in used_extruders:
  608. prime_blob_enabled = extruder.getProperty("prime_blob_enable", "value")
  609. prime_x = extruder.getProperty("extruder_prime_pos_x", "value")
  610. prime_y = -extruder.getProperty("extruder_prime_pos_y", "value")
  611. #Ignore extruder prime position if it is not set or if blob is disabled
  612. if (prime_x == 0 and prime_y == 0) or not prime_blob_enabled:
  613. result[extruder.getId()] = []
  614. continue
  615. if not self._global_container_stack.getProperty("machine_center_is_zero", "value"):
  616. prime_x = prime_x - machine_width / 2 #Offset by half machine_width and _depth to put the origin in the front-left.
  617. prime_y = prime_y + machine_depth / 2
  618. prime_polygon = Polygon.approximatedCircle(PRIME_CLEARANCE)
  619. prime_polygon = prime_polygon.getMinkowskiHull(Polygon.approximatedCircle(border_size))
  620. prime_polygon = prime_polygon.translate(prime_x, prime_y)
  621. result[extruder.getId()] = [prime_polygon]
  622. return result
  623. ## Computes the disallowed areas that are statically placed in the machine.
  624. #
  625. # It computes different disallowed areas depending on the offset of the
  626. # extruder. The resulting dictionary will therefore have an entry for each
  627. # extruder that is used.
  628. #
  629. # \param border_size The size with which to offset the disallowed areas
  630. # due to skirt, brim, travel avoid distance, etc.
  631. # \param used_extruders The extruder stacks to generate disallowed areas
  632. # for.
  633. # \return A dictionary with for each used extruder ID the disallowed areas
  634. # where that extruder may not print.
  635. def _computeDisallowedAreasStatic(self, border_size, used_extruders):
  636. #Convert disallowed areas to polygons and dilate them.
  637. machine_disallowed_polygons = []
  638. for area in self._global_container_stack.getProperty("machine_disallowed_areas", "value"):
  639. polygon = Polygon(numpy.array(area, numpy.float32))
  640. polygon = polygon.getMinkowskiHull(Polygon.approximatedCircle(border_size))
  641. machine_disallowed_polygons.append(polygon)
  642. # For certain machines we don't need to compute disallowed areas for each nozzle.
  643. # So we check here and only do the nozzle offsetting if needed.
  644. nozzle_offsetting_for_disallowed_areas = self._global_container_stack.getMetaDataEntry(
  645. "nozzle_offsetting_for_disallowed_areas", True)
  646. result = {}
  647. for extruder in used_extruders:
  648. extruder_id = extruder.getId()
  649. offset_x = extruder.getProperty("machine_nozzle_offset_x", "value")
  650. if offset_x is None:
  651. offset_x = 0
  652. offset_y = extruder.getProperty("machine_nozzle_offset_y", "value")
  653. if offset_y is None:
  654. offset_y = 0
  655. result[extruder_id] = []
  656. for polygon in machine_disallowed_polygons:
  657. result[extruder_id].append(polygon.translate(offset_x, offset_y)) #Compensate for the nozzle offset of this extruder.
  658. #Add the border around the edge of the build volume.
  659. left_unreachable_border = 0
  660. right_unreachable_border = 0
  661. top_unreachable_border = 0
  662. bottom_unreachable_border = 0
  663. # Only do nozzle offsetting if needed
  664. if nozzle_offsetting_for_disallowed_areas:
  665. #The build volume is defined as the union of the area that all extruders can reach, so we need to know the relative offset to all extruders.
  666. for other_extruder in ExtruderManager.getInstance().getActiveExtruderStacks():
  667. other_offset_x = other_extruder.getProperty("machine_nozzle_offset_x", "value")
  668. if other_offset_x is None:
  669. other_offset_x = 0
  670. other_offset_y = other_extruder.getProperty("machine_nozzle_offset_y", "value")
  671. if other_offset_y is None:
  672. other_offset_y = 0
  673. other_offset_y = -other_offset_y
  674. left_unreachable_border = min(left_unreachable_border, other_offset_x - offset_x)
  675. right_unreachable_border = max(right_unreachable_border, other_offset_x - offset_x)
  676. top_unreachable_border = min(top_unreachable_border, other_offset_y - offset_y)
  677. bottom_unreachable_border = max(bottom_unreachable_border, other_offset_y - offset_y)
  678. half_machine_width = self._global_container_stack.getProperty("machine_width", "value") / 2
  679. half_machine_depth = self._global_container_stack.getProperty("machine_depth", "value") / 2
  680. if self._shape != "elliptic":
  681. if border_size - left_unreachable_border > 0:
  682. result[extruder_id].append(Polygon(numpy.array([
  683. [-half_machine_width, -half_machine_depth],
  684. [-half_machine_width, half_machine_depth],
  685. [-half_machine_width + border_size - left_unreachable_border, half_machine_depth - border_size - bottom_unreachable_border],
  686. [-half_machine_width + border_size - left_unreachable_border, -half_machine_depth + border_size - top_unreachable_border]
  687. ], numpy.float32)))
  688. if border_size + right_unreachable_border > 0:
  689. result[extruder_id].append(Polygon(numpy.array([
  690. [half_machine_width, half_machine_depth],
  691. [half_machine_width, -half_machine_depth],
  692. [half_machine_width - border_size - right_unreachable_border, -half_machine_depth + border_size - top_unreachable_border],
  693. [half_machine_width - border_size - right_unreachable_border, half_machine_depth - border_size - bottom_unreachable_border]
  694. ], numpy.float32)))
  695. if border_size + bottom_unreachable_border > 0:
  696. result[extruder_id].append(Polygon(numpy.array([
  697. [-half_machine_width, half_machine_depth],
  698. [half_machine_width, half_machine_depth],
  699. [half_machine_width - border_size - right_unreachable_border, half_machine_depth - border_size - bottom_unreachable_border],
  700. [-half_machine_width + border_size - left_unreachable_border, half_machine_depth - border_size - bottom_unreachable_border]
  701. ], numpy.float32)))
  702. if border_size - top_unreachable_border > 0:
  703. result[extruder_id].append(Polygon(numpy.array([
  704. [half_machine_width, -half_machine_depth],
  705. [-half_machine_width, -half_machine_depth],
  706. [-half_machine_width + border_size - left_unreachable_border, -half_machine_depth + border_size - top_unreachable_border],
  707. [half_machine_width - border_size - right_unreachable_border, -half_machine_depth + border_size - top_unreachable_border]
  708. ], numpy.float32)))
  709. else:
  710. sections = 32
  711. arc_vertex = [0, half_machine_depth - border_size]
  712. for i in range(0, sections):
  713. quadrant = math.floor(4 * i / sections)
  714. vertices = []
  715. if quadrant == 0:
  716. vertices.append([-half_machine_width, half_machine_depth])
  717. elif quadrant == 1:
  718. vertices.append([-half_machine_width, -half_machine_depth])
  719. elif quadrant == 2:
  720. vertices.append([half_machine_width, -half_machine_depth])
  721. elif quadrant == 3:
  722. vertices.append([half_machine_width, half_machine_depth])
  723. vertices.append(arc_vertex)
  724. angle = 2 * math.pi * (i + 1) / sections
  725. arc_vertex = [-(half_machine_width - border_size) * math.sin(angle), (half_machine_depth - border_size) * math.cos(angle)]
  726. vertices.append(arc_vertex)
  727. result[extruder_id].append(Polygon(numpy.array(vertices, numpy.float32)))
  728. if border_size > 0:
  729. result[extruder_id].append(Polygon(numpy.array([
  730. [-half_machine_width, -half_machine_depth],
  731. [-half_machine_width, half_machine_depth],
  732. [-half_machine_width + border_size, 0]
  733. ], numpy.float32)))
  734. result[extruder_id].append(Polygon(numpy.array([
  735. [-half_machine_width, half_machine_depth],
  736. [ half_machine_width, half_machine_depth],
  737. [ 0, half_machine_depth - border_size]
  738. ], numpy.float32)))
  739. result[extruder_id].append(Polygon(numpy.array([
  740. [ half_machine_width, half_machine_depth],
  741. [ half_machine_width, -half_machine_depth],
  742. [ half_machine_width - border_size, 0]
  743. ], numpy.float32)))
  744. result[extruder_id].append(Polygon(numpy.array([
  745. [ half_machine_width,-half_machine_depth],
  746. [-half_machine_width,-half_machine_depth],
  747. [ 0, -half_machine_depth + border_size]
  748. ], numpy.float32)))
  749. return result
  750. ## Private convenience function to get a setting from the adhesion
  751. # extruder.
  752. #
  753. # \param setting_key The key of the setting to get.
  754. # \param property The property to get from the setting.
  755. # \return The property of the specified setting in the adhesion extruder.
  756. def _getSettingFromAdhesionExtruder(self, setting_key, property = "value"):
  757. return self._getSettingFromExtruder(setting_key, "adhesion_extruder_nr", property)
  758. ## Private convenience function to get a setting from every extruder.
  759. #
  760. # For single extrusion machines, this gets the setting from the global
  761. # stack.
  762. #
  763. # \return A sequence of setting values, one for each extruder.
  764. def _getSettingFromAllExtruders(self, setting_key, property = "value"):
  765. all_values = ExtruderManager.getInstance().getAllExtruderSettings(setting_key, property)
  766. all_types = ExtruderManager.getInstance().getAllExtruderSettings(setting_key, "type")
  767. for i in range(len(all_values)):
  768. if not all_values[i] and (all_types[i] == "int" or all_types[i] == "float"):
  769. all_values[i] = 0
  770. return all_values
  771. ## Private convenience function to get a setting from the support infill
  772. # extruder.
  773. #
  774. # \param setting_key The key of the setting to get.
  775. # \param property The property to get from the setting.
  776. # \return The property of the specified setting in the support infill
  777. # extruder.
  778. def _getSettingFromSupportInfillExtruder(self, setting_key, property = "value"):
  779. return self._getSettingFromExtruder(setting_key, "support_infill_extruder_nr", property)
  780. ## Helper function to get a setting from an extruder specified in another
  781. # setting.
  782. #
  783. # \param setting_key The key of the setting to get.
  784. # \param extruder_setting_key The key of the setting that specifies from
  785. # which extruder to get the setting, if there are multiple extruders.
  786. # \param property The property to get from the setting.
  787. # \return The property of the specified setting in the specified extruder.
  788. def _getSettingFromExtruder(self, setting_key, extruder_setting_key, property = "value"):
  789. multi_extrusion = self._global_container_stack.getProperty("machine_extruder_count", "value") > 1
  790. if not multi_extrusion:
  791. stack = self._global_container_stack
  792. else:
  793. extruder_index = self._global_container_stack.getProperty(extruder_setting_key, "value")
  794. if str(extruder_index) == "-1": # If extruder index is -1 use global instead
  795. stack = self._global_container_stack
  796. else:
  797. extruder_stack_id = ExtruderManager.getInstance().extruderIds[str(extruder_index)]
  798. stack = ContainerRegistry.getInstance().findContainerStacks(id = extruder_stack_id)[0]
  799. value = stack.getProperty(setting_key, property)
  800. setting_type = stack.getProperty(setting_key, "type")
  801. if not value and (setting_type == "int" or setting_type == "float"):
  802. return 0
  803. return value
  804. ## Convenience function to calculate the disallowed radius around the edge.
  805. #
  806. # This disallowed radius is to allow for space around the models that is
  807. # not part of the collision radius, such as bed adhesion (skirt/brim/raft)
  808. # and travel avoid distance.
  809. def _getEdgeDisallowedSize(self):
  810. if not self._global_container_stack:
  811. return 0
  812. container_stack = self._global_container_stack
  813. used_extruders = ExtruderManager.getInstance().getUsedExtruderStacks()
  814. # If we are printing one at a time, we need to add the bed adhesion size to the disallowed areas of the objects
  815. if container_stack.getProperty("print_sequence", "value") == "one_at_a_time":
  816. return 0.1 # Return a very small value, so we do draw disallowed area's near the edges.
  817. adhesion_type = container_stack.getProperty("adhesion_type", "value")
  818. if adhesion_type == "skirt":
  819. skirt_distance = self._getSettingFromAdhesionExtruder("skirt_gap")
  820. skirt_line_count = self._getSettingFromAdhesionExtruder("skirt_line_count")
  821. bed_adhesion_size = skirt_distance + (skirt_line_count * self._getSettingFromAdhesionExtruder("skirt_brim_line_width")) * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
  822. if len(used_extruders) > 1:
  823. for extruder_stack in used_extruders:
  824. bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
  825. #We don't create an additional line for the extruder we're printing the skirt with.
  826. bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
  827. elif adhesion_type == "brim":
  828. bed_adhesion_size = self._getSettingFromAdhesionExtruder("brim_line_count") * self._getSettingFromAdhesionExtruder("skirt_brim_line_width") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor") / 100.0
  829. if self._global_container_stack.getProperty("machine_extruder_count", "value") > 1:
  830. for extruder_stack in used_extruders:
  831. bed_adhesion_size += extruder_stack.getProperty("skirt_brim_line_width", "value") * extruder_stack.getProperty("initial_layer_line_width_factor", "value") / 100.0
  832. #We don't create an additional line for the extruder we're printing the brim with.
  833. bed_adhesion_size -= self._getSettingFromAdhesionExtruder("skirt_brim_line_width", "value") * self._getSettingFromAdhesionExtruder("initial_layer_line_width_factor", "value") / 100.0
  834. elif adhesion_type == "raft":
  835. bed_adhesion_size = self._getSettingFromAdhesionExtruder("raft_margin")
  836. elif adhesion_type == "none":
  837. bed_adhesion_size = 0
  838. else:
  839. raise Exception("Unknown bed adhesion type. Did you forget to update the build volume calculations for your new bed adhesion type?")
  840. support_expansion = 0
  841. if self._getSettingFromSupportInfillExtruder("support_offset") and self._global_container_stack.getProperty("support_enable", "value"):
  842. support_expansion += self._getSettingFromSupportInfillExtruder("support_offset")
  843. farthest_shield_distance = 0
  844. if container_stack.getProperty("draft_shield_enabled", "value"):
  845. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("draft_shield_dist", "value"))
  846. if container_stack.getProperty("ooze_shield_enabled", "value"):
  847. farthest_shield_distance = max(farthest_shield_distance, container_stack.getProperty("ooze_shield_dist", "value"))
  848. move_from_wall_radius = 0 # Moves that start from outer wall.
  849. move_from_wall_radius = max(move_from_wall_radius, max(self._getSettingFromAllExtruders("infill_wipe_dist")))
  850. avoid_enabled_per_extruder = [stack.getProperty("travel_avoid_other_parts","value") for stack in used_extruders]
  851. travel_avoid_distance_per_extruder = [stack.getProperty("travel_avoid_distance", "value") for stack in used_extruders]
  852. for avoid_other_parts_enabled, avoid_distance in zip(avoid_enabled_per_extruder, travel_avoid_distance_per_extruder): #For each extruder (or just global).
  853. if avoid_other_parts_enabled:
  854. move_from_wall_radius = max(move_from_wall_radius, avoid_distance)
  855. # Now combine our different pieces of data to get the final border size.
  856. # Support expansion is added to the bed adhesion, since the bed adhesion goes around support.
  857. # Support expansion is added to farthest shield distance, since the shields go around support.
  858. border_size = max(move_from_wall_radius, support_expansion + farthest_shield_distance, support_expansion + bed_adhesion_size)
  859. return border_size
  860. def _clamp(self, value, min_value, max_value):
  861. return max(min(value, max_value), min_value)
  862. _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", "initial_layer_line_width_factor"]
  863. _raft_settings = ["adhesion_type", "raft_base_thickness", "raft_interface_thickness", "raft_surface_layers", "raft_surface_thickness", "raft_airgap", "layer_0_z_overlap"]
  864. _extra_z_settings = ["retraction_hop_enabled", "retraction_hop"]
  865. _prime_settings = ["extruder_prime_pos_x", "extruder_prime_pos_y", "extruder_prime_pos_z", "prime_blob_enable"]
  866. _tower_settings = ["prime_tower_enable", "prime_tower_size", "prime_tower_position_x", "prime_tower_position_y"]
  867. _ooze_shield_settings = ["ooze_shield_enabled", "ooze_shield_dist"]
  868. _distance_settings = ["infill_wipe_dist", "travel_avoid_distance", "support_offset", "support_enable", "travel_avoid_other_parts"]
  869. _extruder_settings = ["support_enable", "support_bottom_enable", "support_roof_enable", "support_infill_extruder_nr", "support_extruder_nr_layer_0", "support_bottom_extruder_nr", "support_roof_extruder_nr", "brim_line_count", "adhesion_extruder_nr", "adhesion_type"] #Settings that can affect which extruders are used.
  870. _limit_to_extruder_settings = ["wall_extruder_nr", "wall_0_extruder_nr", "wall_x_extruder_nr", "top_bottom_extruder_nr", "infill_extruder_nr", "support_infill_extruder_nr", "support_extruder_nr_layer_0", "support_bottom_extruder_nr", "support_roof_extruder_nr", "adhesion_extruder_nr"]