BuildVolume.py 54 KB

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