From d7901907aff0709c65d0f79439e073c8d3983c8d Mon Sep 17 00:00:00 2001 From: Jaime van Kessel Date: Thu, 27 Sep 2018 15:37:08 +0200 Subject: [PATCH] Fix typing --- cura/PrinterOutput/ConfigurationModel.py | 16 ++++++++-------- cura/Scene/ConvexHullDecorator.py | 21 +++++++++++++-------- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/cura/PrinterOutput/ConfigurationModel.py b/cura/PrinterOutput/ConfigurationModel.py index a3d6afd01d..b3e8373745 100644 --- a/cura/PrinterOutput/ConfigurationModel.py +++ b/cura/PrinterOutput/ConfigurationModel.py @@ -13,20 +13,20 @@ class ConfigurationModel(QObject): configurationChanged = pyqtSignal() - def __init__(self): + def __init__(self) -> None: super().__init__() - self._printer_type = None + self._printer_type = "" self._extruder_configurations = [] # type: List[ExtruderConfigurationModel] - self._buildplate_configuration = None + self._buildplate_configuration = "" def setPrinterType(self, printer_type): self._printer_type = printer_type @pyqtProperty(str, fset = setPrinterType, notify = configurationChanged) - def printerType(self): + def printerType(self) -> str: return self._printer_type - def setExtruderConfigurations(self, extruder_configurations): + def setExtruderConfigurations(self, extruder_configurations: List[ExtruderConfigurationModel]): if self._extruder_configurations != extruder_configurations: self._extruder_configurations = extruder_configurations @@ -39,16 +39,16 @@ class ConfigurationModel(QObject): def extruderConfigurations(self): return self._extruder_configurations - def setBuildplateConfiguration(self, buildplate_configuration): + def setBuildplateConfiguration(self, buildplate_configuration: str) -> None: self._buildplate_configuration = buildplate_configuration @pyqtProperty(str, fset = setBuildplateConfiguration, notify = configurationChanged) - def buildplateConfiguration(self): + def buildplateConfiguration(self) -> str: return self._buildplate_configuration ## This method is intended to indicate whether the configuration is valid or not. # The method checks if the mandatory fields are or not set - def isValid(self): + def isValid(self) -> bool: if not self._extruder_configurations: return False for configuration in self._extruder_configurations: diff --git a/cura/Scene/ConvexHullDecorator.py b/cura/Scene/ConvexHullDecorator.py index a78f559aa1..31e21df6bf 100644 --- a/cura/Scene/ConvexHullDecorator.py +++ b/cura/Scene/ConvexHullDecorator.py @@ -78,7 +78,7 @@ class ConvexHullDecorator(SceneNodeDecorator): hull = self._compute2DConvexHull() - if self._global_stack and self._node: + if self._global_stack and self._node and hull is not None: # Parent can be None if node is just loaded. if self._global_stack.getProperty("print_sequence", "value") == "one_at_a_time" and (self._node.getParent() is None or not self._node.getParent().callDecoration("isGroup")): hull = hull.getMinkowskiHull(Polygon(numpy.array(self._global_stack.getProperty("machine_head_polygon", "value"), numpy.float32))) @@ -240,17 +240,22 @@ class ConvexHullDecorator(SceneNodeDecorator): return Polygon(numpy.array(self._global_stack.getHeadAndFansCoordinates(), numpy.float32)) return Polygon() - def _compute2DConvexHeadFull(self) -> Polygon: - return self._compute2DConvexHull().getMinkowskiHull(self._getHeadAndFans()) + def _compute2DConvexHeadFull(self) -> Optional[Polygon]: + convex_hull = self._compute2DConvexHeadFull() + if convex_hull: + return convex_hull.getMinkowskiHull(self._getHeadAndFans()) + return None - def _compute2DConvexHeadMin(self) -> Polygon: - headAndFans = self._getHeadAndFans() - mirrored = headAndFans.mirror([0, 0], [0, 1]).mirror([0, 0], [1, 0]) # Mirror horizontally & vertically. + def _compute2DConvexHeadMin(self) -> Optional[Polygon]: + head_and_fans = self._getHeadAndFans() + mirrored = head_and_fans.mirror([0, 0], [0, 1]).mirror([0, 0], [1, 0]) # Mirror horizontally & vertically. head_and_fans = self._getHeadAndFans().intersectionConvexHulls(mirrored) # Min head hull is used for the push free - min_head_hull = self._compute2DConvexHull().getMinkowskiHull(head_and_fans) - return min_head_hull + convex_hull = self._compute2DConvexHeadFull() + if convex_hull: + return convex_hull.getMinkowskiHull(head_and_fans) + return None ## Compensate given 2D polygon with adhesion margin # \return 2D polygon with added margin