BuildVolume.py 54 KB

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