Add casts for result of deepcopy

Because deepcopy should return the same object as what is provided as input.

Contributes to issue CURA-5330.
This commit is contained in:
Ghostkeeper 2018-06-04 09:48:30 +02:00
parent 9fb4511f52
commit aff341eac9
No known key found for this signature in database
GPG key ID: 5252B696FB5E7C7A

View file

@ -2,12 +2,13 @@
# Cura is released under the terms of the LGPLv3 or higher.
from copy import deepcopy
from typing import Dict, List, Optional
from typing import cast, Dict, List, Optional
from UM.Application import Application
from UM.Math.AxisAlignedBox import AxisAlignedBox
from UM.Math.Polygon import Polygon #For typing.
from UM.Scene.SceneNode import SceneNode
from UM.Scene.SceneNodeDecorator import SceneNodeDecorator #To cast the deepcopy of every decorator back to SceneNodeDecorator.
from cura.CuraApplication import CuraApplication #To get the build plate.
from cura.Settings.ExtruderStack import ExtruderStack #For typing.
@ -129,14 +130,14 @@ class CuraSceneNode(SceneNode):
copy = CuraSceneNode(no_setting_override = True) # Setting override will be added later
copy.setTransformation(self.getLocalTransformation())
copy.setMeshData(self._mesh_data)
copy.setVisible(deepcopy(self._visible, memo))
copy._selectable = deepcopy(self._selectable, memo)
copy._name = deepcopy(self._name, memo)
copy.setVisible(cast(bool, deepcopy(self._visible, memo)))
copy._selectable = cast(bool, deepcopy(self._selectable, memo))
copy._name = cast(str, deepcopy(self._name, memo))
for decorator in self._decorators:
copy.addDecorator(deepcopy(decorator, memo))
copy.addDecorator(cast(SceneNodeDecorator, deepcopy(decorator, memo)))
for child in self._children:
copy.addChild(deepcopy(child, memo))
copy.addChild(cast(SceneNode, deepcopy(child, memo)))
self.calculateBoundingBoxMesh()
return copy