diff --git a/cura/Scene/ConvexHullDecorator.py b/cura/Scene/ConvexHullDecorator.py index 85d1e8e309..a78f559aa1 100644 --- a/cura/Scene/ConvexHullDecorator.py +++ b/cura/Scene/ConvexHullDecorator.py @@ -15,8 +15,6 @@ import numpy from typing import TYPE_CHECKING, Any, Optional - - if TYPE_CHECKING: from UM.Scene.SceneNode import SceneNode from cura.Settings.GlobalStack import GlobalStack @@ -35,10 +33,11 @@ class ConvexHullDecorator(SceneNodeDecorator): # Make sure the timer is created on the main thread self._recompute_convex_hull_timer = None # type: Optional[QTimer] - Application.getInstance().callLater(self.createRecomputeConvexHullTimer) + + if Application.getInstance() is not None: + Application.getInstance().callLater(self.createRecomputeConvexHullTimer) self._raft_thickness = 0.0 - # For raft thickness, DRY self._build_volume = Application.getInstance().getBuildVolume() self._build_volume.raftThicknessChanged.connect(self._onChanged) @@ -72,7 +71,7 @@ class ConvexHullDecorator(SceneNodeDecorator): def __deepcopy__(self, memo): return ConvexHullDecorator() - ## Get the unmodified 2D projected convex hull of the node + ## Get the unmodified 2D projected convex hull of the node (if any) def getConvexHull(self) -> Optional[Polygon]: if self._node is None: return None @@ -120,6 +119,7 @@ class ConvexHullDecorator(SceneNodeDecorator): return self._compute2DConvexHull() return None + ## The same as recomputeConvexHull, but using a timer if it was set. def recomputeConvexHullDelayed(self) -> None: if self._recompute_convex_hull_timer is not None: self._recompute_convex_hull_timer.start() @@ -142,13 +142,13 @@ class ConvexHullDecorator(SceneNodeDecorator): self._convex_hull_node = hull_node def _onSettingValueChanged(self, key: str, property_name: str) -> None: - if property_name != "value": #Not the value that was changed. + if property_name != "value": # Not the value that was changed. return if key in self._affected_settings: self._onChanged() if key in self._influencing_settings: - self._init2DConvexHullCache() #Invalidate the cache. + self._init2DConvexHullCache() # Invalidate the cache. self._onChanged() def _init2DConvexHullCache(self) -> None: @@ -161,7 +161,7 @@ class ConvexHullDecorator(SceneNodeDecorator): self._2d_convex_hull_mesh_world_transform = None self._2d_convex_hull_mesh_result = None - def _compute2DConvexHull(self) -> Polygon: + def _compute2DConvexHull(self) -> Optional[Polygon]: if self._node.callDecoration("isGroup"): points = numpy.zeros((0, 2), dtype=numpy.int32) for child in self._node.getChildren(): @@ -188,8 +188,6 @@ class ConvexHullDecorator(SceneNodeDecorator): else: offset_hull = None - mesh = None - world_transform = None if self._node.getMeshData(): mesh = self._node.getMeshData() world_transform = self._node.getWorldTransformation() @@ -242,10 +240,10 @@ class ConvexHullDecorator(SceneNodeDecorator): return Polygon(numpy.array(self._global_stack.getHeadAndFansCoordinates(), numpy.float32)) return Polygon() - def _compute2DConvexHeadFull(self): + def _compute2DConvexHeadFull(self) -> Polygon: return self._compute2DConvexHull().getMinkowskiHull(self._getHeadAndFans()) - def _compute2DConvexHeadMin(self): + def _compute2DConvexHeadMin(self) -> Polygon: headAndFans = self._getHeadAndFans() mirrored = headAndFans.mirror([0, 0], [0, 1]).mirror([0, 0], [1, 0]) # Mirror horizontally & vertically. head_and_fans = self._getHeadAndFans().intersectionConvexHulls(mirrored) @@ -276,7 +274,7 @@ class ConvexHullDecorator(SceneNodeDecorator): else: raise Exception("Unknown bed adhesion type. Did you forget to update the convex hull calculations for your new bed adhesion type?") - # adjust head_and_fans with extra margin + # Adjust head_and_fans with extra margin if extra_margin > 0: extra_margin_polygon = Polygon.approximatedCircle(extra_margin) poly = poly.getMinkowskiHull(extra_margin_polygon) @@ -354,7 +352,7 @@ class ConvexHullDecorator(SceneNodeDecorator): # Limit_to_extruder is set. The global stack handles this then return self._global_stack.getProperty(setting_key, prop) - ## Returns true if node is a descendant or the same as the root node. + ## Returns True if node is a descendant or the same as the root node. def __isDescendant(self, root: "SceneNode", node: "SceneNode") -> bool: if node is None: return False