|
@@ -1,39 +1,42 @@
|
|
|
# Copyright (c) 2018 Ultimaker B.V.
|
|
|
# Cura is released under the terms of the LGPLv3 or higher.
|
|
|
+
|
|
|
from copy import deepcopy
|
|
|
-from typing import List
|
|
|
+from typing import 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 cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator
|
|
|
-
|
|
|
+from cura.CuraApplication import CuraApplication #To get the build plate.
|
|
|
+from cura.Settings.ExtruderStack import ExtruderStack #For typing.
|
|
|
+from cura.Settings.SettingOverrideDecorator import SettingOverrideDecorator #For per-object settings.
|
|
|
|
|
|
## Scene nodes that are models are only seen when selecting the corresponding build plate
|
|
|
# Note that many other nodes can just be UM SceneNode objects.
|
|
|
class CuraSceneNode(SceneNode):
|
|
|
- def __init__(self, *args, **kwargs):
|
|
|
- super().__init__(*args, **kwargs)
|
|
|
- if "no_setting_override" not in kwargs:
|
|
|
- self.addDecorator(SettingOverrideDecorator()) # now we always have a getActiveExtruderPosition, unless explicitly disabled
|
|
|
+ def __init__(self, parent: Optional["SceneNode"] = None, visible: bool = True, name: str = "", no_setting_override: bool = False) -> None:
|
|
|
+ super().__init__(parent = parent, visible = visible, name = name)
|
|
|
+ if not no_setting_override:
|
|
|
+ self.addDecorator(SettingOverrideDecorator())
|
|
|
self._outside_buildarea = False
|
|
|
|
|
|
- def setOutsideBuildArea(self, new_value):
|
|
|
+ def setOutsideBuildArea(self, new_value: bool) -> None:
|
|
|
self._outside_buildarea = new_value
|
|
|
|
|
|
- def isOutsideBuildArea(self):
|
|
|
+ def isOutsideBuildArea(self) -> bool:
|
|
|
return self._outside_buildarea or self.callDecoration("getBuildPlateNumber") < 0
|
|
|
|
|
|
- def isVisible(self):
|
|
|
- return super().isVisible() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
|
|
|
+ def isVisible(self) -> bool:
|
|
|
+ return super().isVisible() and self.callDecoration("getBuildPlateNumber") == CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
|
|
|
|
|
|
def isSelectable(self) -> bool:
|
|
|
- return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == Application.getInstance().getMultiBuildPlateModel().activeBuildPlate
|
|
|
+ return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == CuraApplication.getInstance().getMultiBuildPlateModel().activeBuildPlate
|
|
|
|
|
|
## Get the extruder used to print this node. If there is no active node, then the extruder in position zero is returned
|
|
|
# TODO The best way to do it is by adding the setActiveExtruder decorator to every node when is loaded
|
|
|
- def getPrintingExtruder(self):
|
|
|
+ def getPrintingExtruder(self) -> Optional[ExtruderStack]:
|
|
|
global_container_stack = Application.getInstance().getGlobalContainerStack()
|
|
|
per_mesh_stack = self.callDecoration("getStack")
|
|
|
extruders = list(global_container_stack.extruders.values())
|
|
@@ -79,7 +82,7 @@ class CuraSceneNode(SceneNode):
|
|
|
]
|
|
|
|
|
|
## Return if the provided bbox collides with the bbox of this scene node
|
|
|
- def collidesWithBbox(self, check_bbox):
|
|
|
+ def collidesWithBbox(self, check_bbox: AxisAlignedBox) -> bool:
|
|
|
bbox = self.getBoundingBox()
|
|
|
|
|
|
# Mark the node as outside the build volume if the bounding box test fails.
|
|
@@ -89,7 +92,7 @@ class CuraSceneNode(SceneNode):
|
|
|
return False
|
|
|
|
|
|
## Return if any area collides with the convex hull of this scene node
|
|
|
- def collidesWithArea(self, areas):
|
|
|
+ def collidesWithArea(self, areas: List[Polygon]) -> bool:
|
|
|
convex_hull = self.callDecoration("getConvexHull")
|
|
|
if convex_hull:
|
|
|
if not convex_hull.isValid():
|
|
@@ -104,8 +107,7 @@ class CuraSceneNode(SceneNode):
|
|
|
return False
|
|
|
|
|
|
## Override of SceneNode._calculateAABB to exclude non-printing-meshes from bounding box
|
|
|
- def _calculateAABB(self):
|
|
|
- aabb = None
|
|
|
+ def _calculateAABB(self) -> None:
|
|
|
if self._mesh_data:
|
|
|
aabb = self._mesh_data.getExtents(self.getWorldTransformation())
|
|
|
else: # If there is no mesh_data, use a boundingbox that encompasses the local (0,0,0)
|
|
@@ -123,7 +125,7 @@ class CuraSceneNode(SceneNode):
|
|
|
self._aabb = aabb
|
|
|
|
|
|
## Taken from SceneNode, but replaced SceneNode with CuraSceneNode
|
|
|
- def __deepcopy__(self, memo):
|
|
|
+ def __deepcopy__(self, memo: Dict[int, object]) -> "CuraSceneNode":
|
|
|
copy = CuraSceneNode(no_setting_override = True) # Setting override will be added later
|
|
|
copy.setTransformation(self.getLocalTransformation())
|
|
|
copy.setMeshData(self._mesh_data)
|