Fixed up the convex hull 'shadow' creation and deletion after the merge.

Contributes to CURA-1504
This commit is contained in:
Simon Edwards 2016-06-22 14:48:15 +02:00
parent fd42a43270
commit 9641a25f31
3 changed files with 28 additions and 19 deletions

View file

@ -19,6 +19,19 @@ class ConvexHullDecorator(SceneNodeDecorator):
Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged) Application.getInstance().globalContainerStackChanged.connect(self._onGlobalStackChanged)
self._onGlobalStackChanged() self._onGlobalStackChanged()
def setNode(self, node):
previous_node = self._node
if previous_node is not None and node is not previous_node:
previous_node.transformationChanged.connect(self._onChanged)
previous_node.parentChanged.connect(self._onChanged)
super().setNode(node)
self._node.transformationChanged.connect(self._onChanged)
self._node.parentChanged.connect(self._onChanged)
self._onChanged()
## Force that a new (empty) object is created upon copy. ## Force that a new (empty) object is created upon copy.
def __deepcopy__(self, memo): def __deepcopy__(self, memo):
return ConvexHullDecorator() return ConvexHullDecorator()
@ -67,16 +80,19 @@ class ConvexHullDecorator(SceneNodeDecorator):
return None return None
def recomputeConvexHull(self): def recomputeConvexHull(self):
if self._node is None: root = Application.getInstance().getController().getScene().getRoot()
return None if self._node is None or not self.__isDescendant(root, self._node):
if self._convex_hull_node:
self._convex_hull_node.setParent(None)
self._convex_hull_node = None
return
convex_hull = self.getConvexHull() convex_hull = self.getConvexHull()
if self._convex_hull_node: if self._convex_hull_node:
if self._convex_hull_node.getHull() == convex_hull: if self._convex_hull_node.getHull() == convex_hull:
return return
self._convex_hull_node.setParent(None) self._convex_hull_node.setParent(None)
hull_node = ConvexHullNode.ConvexHullNode(self._node, convex_hull, hull_node = ConvexHullNode.ConvexHullNode(self._node, convex_hull, root)
Application.getInstance().getController().getScene().getRoot())
self._convex_hull_node = hull_node self._convex_hull_node = hull_node
def _onSettingValueChanged(self, key, property_name): def _onSettingValueChanged(self, key, property_name):
@ -205,3 +221,11 @@ class ConvexHullDecorator(SceneNodeDecorator):
self._global_stack.containersChanged.connect(self._onChanged) self._global_stack.containersChanged.connect(self._onChanged)
self._onChanged() self._onChanged()
## Returns true if node is a descendent or the same as the root node.
def __isDescendant(self, root, node):
if node is None:
return False
if root is node:
return True
return self.__isDescendant(root, node.getParent())

View file

@ -1,7 +1,6 @@
# Copyright (c) 2015 Ultimaker B.V. # Copyright (c) 2015 Ultimaker B.V.
# Cura is released under the terms of the AGPLv3 or higher. # Cura is released under the terms of the AGPLv3 or higher.
from UM.Application import Application
from UM.Scene.SceneNode import SceneNode from UM.Scene.SceneNode import SceneNode
from UM.Resources import Resources from UM.Resources import Resources
from UM.Math.Color import Color from UM.Math.Color import Color
@ -31,8 +30,6 @@ class ConvexHullNode(SceneNode):
# The node this mesh is "watching" # The node this mesh is "watching"
self._node = node self._node = node
self._node.transformationChanged.connect(self._onNodePositionChanged)
self._node.parentChanged.connect(self._onNodeParentChanged)
self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged) self._node.decoratorsChanged.connect(self._onNodeDecoratorsChanged)
self._onNodeDecoratorsChanged(self._node) self._onNodeDecoratorsChanged(self._node)
@ -84,17 +81,6 @@ class ConvexHullNode(SceneNode):
return True return True
def _onNodePositionChanged(self, node):
if Application.getInstance().getController().isToolOperationActive():
if node.callDecoration("getConvexHull"):
self.setParent(None) # Garbage collection should delete this node after a while.
def _onNodeParentChanged(self, node):
if node.getParent():
self.setParent(self._original_parent)
else:
self.setParent(None)
def _onNodeDecoratorsChanged(self, node): def _onNodeDecoratorsChanged(self, node):
self._color = Color(35, 35, 35, 0.5) self._color = Color(35, 35, 35, 0.5)

View file

@ -741,7 +741,6 @@ class CuraApplication(QtApplication):
# Add all individual nodes to the selection # Add all individual nodes to the selection
Selection.add(child) Selection.add(child)
child.callDecoration("setConvexHull", None)
op.push() op.push()
# Note: The group removes itself from the scene once all its children have left it, # Note: The group removes itself from the scene once all its children have left it,