diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 7a495b2064..3afb7052af 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -1,9 +1,8 @@ -# Copyright (c) 2017 Ultimaker B.V. +# Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from cura.Scene.CuraSceneNode import CuraSceneNode from cura.Settings.ExtruderManager import ExtruderManager -from UM.Settings.ContainerRegistry import ContainerRegistry from UM.i18n import i18nCatalog from UM.Scene.Platform import Platform from UM.Scene.Iterator.BreadthFirstIterator import BreadthFirstIterator @@ -195,29 +194,51 @@ class BuildVolume(SceneNode): return True - ## For every sliceable node, update outsideBuildArea - def updateNodeBoundaryCheck(self): - root = Application.getInstance().getController().getScene().getRoot() - nodes = list(BreadthFirstIterator(root)) - group_nodes = [] + ## For every sliceable node, update node._outside_buildarea. + def updateAllBoundaryChecks(self): + self.updateNodeBoundaryCheck(Application.getInstance().getController().getScene().getRoot()) - build_volume_bounding_box = self.getBoundingBox() - if build_volume_bounding_box: - # It's over 9000! - build_volume_bounding_box = build_volume_bounding_box.set(bottom=-9001) - else: - # No bounding box. This is triggered when running Cura from command line with a model for the first time - # In that situation there is a model, but no machine (and therefore no build volume. + ## For a single node, update _outside_buildarea. + # + # If the node is a group node, the child nodes will also get updated. + # \param node The node to update the boundary checks of. + def updateNodeBoundaryCheck(self, node: SceneNode): + if not node.callDecoration("isSliceable") and not node.callDecoration("isGroup"): + for child in node.getChildren(): #Still update the children! For instance, the root is not sliceable. + self.updateNodeBoundaryCheck(child) + return #Don't compute for non-sliceable nodes. + + #Mark the node as outside the build volume if the bounding box test fails. + build_volume = self.getBoundingBox() + if build_volume is None: + #No bounding box. This is triggered when running Cura from command line with a model for the first time. + #In that situation there is a model, but no machine (and therefore no build volume). return + build_volume = build_volume.set(bottom = -999999) #Allow models to clip the build plate. This should allow printing but remove the bottom side of the model underneath the build plate. + bounding_box = node.getBoundingBox() + if build_volume.intersectsBox(bounding_box) != AxisAlignedBox.IntersectionResult.FullIntersection: + node._outside_buildarea = True + else: - for node in nodes: - # Need to check group nodes later - self.checkBoundsAndUpdate(node, bounds = build_volume_bounding_box) + #Check for collisions between disallowed areas and the object. + convex_hull = node.callDecoration("getConvexHull") + if not convex_hull or not convex_hull.isValid(): + return + for area in self.getDisallowedAreas(): + overlap = convex_hull.intersectsPolygon(area) + if overlap is not None: + node._outside_buildarea = True + break + else: + node._outside_buildarea = False - # Group nodes should override the _outside_buildarea property of their children. - for group_node in group_nodes: - for child_node in group_node.getAllChildren(): - child_node._outside_buildarea = group_node._outside_buildarea + #Group nodes should override the _outside_buildarea property of their children. + if node.callDecoration("isGroup"): + for child in node.getAllChildren(): + child._outside_buildarea = node._outside_buildarea + else: + for child in node.getChildren(): + self.updateNodeBoundaryCheck(child) ## Update the outsideBuildArea of a single node, given bounds or current build volume def checkBoundsAndUpdate(self, node: CuraSceneNode, bounds: Optional[AxisAlignedBox] = None): @@ -440,7 +461,7 @@ class BuildVolume(SceneNode): Application.getInstance().getController().getScene()._maximum_bounds = scale_to_max_bounds - self.updateNodeBoundaryCheck() + self.updateAllBoundaryChecks() def getBoundingBox(self) -> AxisAlignedBox: return self._volume_aabb diff --git a/cura/PlatformPhysics.py b/cura/PlatformPhysics.py index 69890178e4..05385d7c71 100755 --- a/cura/PlatformPhysics.py +++ b/cura/PlatformPhysics.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015 Ultimaker B.V. +# Copyright (c) 2018 Ultimaker B.V. # Cura is released under the terms of the LGPLv3 or higher. from PyQt5.QtCore import QTimer @@ -56,14 +56,17 @@ class PlatformPhysics: # By shuffling the order of the nodes, this might happen a few times, but at some point it will resolve. nodes = list(BreadthFirstIterator(root)) - # Only check nodes inside build area. - nodes = [node for node in nodes if (hasattr(node, "_outside_buildarea") and not node._outside_buildarea)] - random.shuffle(nodes) for node in nodes: if node is root or not isinstance(node, SceneNode) or node.getBoundingBox() is None: continue + #Only check nodes inside the build area. + if not hasattr(node, "_outside_buildarea"): + self._build_volume.updateNodeBoundaryCheck(node) + if getattr(node, "_outside_buildarea", True): + continue + bbox = node.getBoundingBox() # Move it downwards if bottom is above platform @@ -155,7 +158,7 @@ class PlatformPhysics: # After moving, we have to evaluate the boundary checks for nodes build_volume = Application.getInstance().getBuildVolume() - build_volume.updateNodeBoundaryCheck() + build_volume.updateAllBoundaryChecks() def _onToolOperationStarted(self, tool): self._enabled = False diff --git a/cura/Scene/CuraSceneNode.py b/cura/Scene/CuraSceneNode.py index 1635d37b5d..e66499c542 100644 --- a/cura/Scene/CuraSceneNode.py +++ b/cura/Scene/CuraSceneNode.py @@ -1,6 +1,7 @@ +# Copyright (c) 2018 Ultimaker B.V. +# Cura is released under the terms of the LGPLv3 or higher. + from UM.Application import Application -from UM.Logger import Logger -from UM.Math.AxisAlignedBox import AxisAlignedBox from UM.Scene.SceneNode import SceneNode from copy import deepcopy diff --git a/resources/definitions/fdmprinter.def.json b/resources/definitions/fdmprinter.def.json index f792731022..aef5533ead 100644 --- a/resources/definitions/fdmprinter.def.json +++ b/resources/definitions/fdmprinter.def.json @@ -5339,7 +5339,7 @@ }, "infill_enable_travel_optimization": { - "label": "Enable Travel Optimization", + "label": "Infill Travel Optimization", "description": "When enabled, the order in which the infill lines are printed is optimized to reduce the distance travelled. The reduction in travel time achieved very much depends on the model being sliced, infill pattern, density, etc. Note that, for some models that have many small areas of infill, the time to slice the model may be greatly increased.", "type": "bool", "default_value": false,