From 8a53549bce61ec6df04297574ee21a09c3983d6d Mon Sep 17 00:00:00 2001 From: Jack Ha Date: Wed, 17 Jan 2018 17:01:03 +0100 Subject: [PATCH] CURA-4033 split update bounds for a single node in buildvolume and also call it from readMeshFinished --- cura/BuildVolume.py | 68 +++++++++++++++++++++++-------------- cura/CuraApplication.py | 1 + cura/Scene/CuraSceneNode.py | 1 + 3 files changed, 44 insertions(+), 26 deletions(-) diff --git a/cura/BuildVolume.py b/cura/BuildVolume.py index 2567641cc9..7a495b2064 100755 --- a/cura/BuildVolume.py +++ b/cura/BuildVolume.py @@ -1,6 +1,7 @@ # Copyright (c) 2017 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 @@ -25,7 +26,7 @@ catalog = i18nCatalog("cura") import numpy import math -from typing import List +from typing import List, Optional # Setting for clearance around the prime PRIME_CLEARANCE = 6.5 @@ -194,8 +195,7 @@ class BuildVolume(SceneNode): return True - ## For every sliceable node, update node._outside_buildarea - # + ## For every sliceable node, update outsideBuildArea def updateNodeBoundaryCheck(self): root = Application.getInstance().getController().getScene().getRoot() nodes = list(BreadthFirstIterator(root)) @@ -212,35 +212,51 @@ class BuildVolume(SceneNode): for node in nodes: # Need to check group nodes later - if node.callDecoration("isGroup"): - group_nodes.append(node) # Keep list of affected group_nodes - - if node.callDecoration("isSliceable") or node.callDecoration("isGroup"): - node._outside_buildarea = False - bbox = node.getBoundingBox() - - # Mark the node as outside the build volume if the bounding box test fails. - if build_volume_bounding_box.intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection: - node._outside_buildarea = True - continue - - convex_hull = node.callDecoration("getConvexHull") - if convex_hull: - if not convex_hull.isValid(): - return - # Check for collisions between disallowed areas and the object - for area in self.getDisallowedAreas(): - overlap = convex_hull.intersectsPolygon(area) - if overlap is None: - continue - node._outside_buildarea = True - continue + self.checkBoundsAndUpdate(node, bounds = build_volume_bounding_box) # 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 + ## Update the outsideBuildArea of a single node, given bounds or current build volume + def checkBoundsAndUpdate(self, node: CuraSceneNode, bounds: Optional[AxisAlignedBox] = None): + if not isinstance(node, CuraSceneNode): + return + + if bounds is None: + 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. + return + else: + build_volume_bounding_box = bounds + + if node.callDecoration("isSliceable") or node.callDecoration("isGroup"): + bbox = node.getBoundingBox() + + # Mark the node as outside the build volume if the bounding box test fails. + if build_volume_bounding_box.intersectsBox(bbox) != AxisAlignedBox.IntersectionResult.FullIntersection: + node.setOutsideBuildArea(True) + return + + convex_hull = self.callDecoration("getConvexHull") + if convex_hull: + if not convex_hull.isValid(): + return + # Check for collisions between disallowed areas and the object + for area in self.getDisallowedAreas(): + overlap = convex_hull.intersectsPolygon(area) + if overlap is None: + continue + node.setOutsideBuildArea(True) + return + node.setOutsideBuildArea(False) + ## Recalculates the build volume & disallowed areas. def rebuild(self): if not self._width or not self._height or not self._depth: diff --git a/cura/CuraApplication.py b/cura/CuraApplication.py index ff38a24cc6..0b10ce8735 100755 --- a/cura/CuraApplication.py +++ b/cura/CuraApplication.py @@ -1481,6 +1481,7 @@ class CuraApplication(QtApplication): node.setSelectable(True) node.setName(os.path.basename(filename)) + self.getBuildVolume().checkBoundsAndUpdate(node) extension = os.path.splitext(filename)[1] if extension.lower() in self._non_sliceable_extensions: diff --git a/cura/Scene/CuraSceneNode.py b/cura/Scene/CuraSceneNode.py index 9df2931f0b..c5dcffd2c2 100644 --- a/cura/Scene/CuraSceneNode.py +++ b/cura/Scene/CuraSceneNode.py @@ -1,5 +1,6 @@ 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