diff options
Diffstat (limited to 'cura/Scene')
-rw-r--r-- | cura/Scene/BuildPlateDecorator.py | 3 | ||||
-rw-r--r-- | cura/Scene/ConvexHullDecorator.py | 89 | ||||
-rw-r--r-- | cura/Scene/ConvexHullNode.py | 10 | ||||
-rw-r--r-- | cura/Scene/CuraSceneController.py | 3 | ||||
-rw-r--r-- | cura/Scene/CuraSceneNode.py | 24 | ||||
-rw-r--r-- | cura/Scene/ZOffsetDecorator.py | 3 |
6 files changed, 85 insertions, 47 deletions
diff --git a/cura/Scene/BuildPlateDecorator.py b/cura/Scene/BuildPlateDecorator.py index cff9f88f62..9dd9d3dc24 100644 --- a/cura/Scene/BuildPlateDecorator.py +++ b/cura/Scene/BuildPlateDecorator.py @@ -2,8 +2,9 @@ from UM.Scene.SceneNodeDecorator import SceneNodeDecorator from cura.Scene.CuraSceneNode import CuraSceneNode -## Make a SceneNode build plate aware CuraSceneNode objects all have this decorator. class BuildPlateDecorator(SceneNodeDecorator): + """Make a SceneNode build plate aware CuraSceneNode objects all have this decorator.""" + def __init__(self, build_plate_number: int = -1) -> None: super().__init__() self._build_plate_number = build_plate_number diff --git a/cura/Scene/ConvexHullDecorator.py b/cura/Scene/ConvexHullDecorator.py index b5f5fb4540..3dee409761 100644 --- a/cura/Scene/ConvexHullDecorator.py +++ b/cura/Scene/ConvexHullDecorator.py @@ -23,9 +23,12 @@ if TYPE_CHECKING: from UM.Math.Matrix import Matrix -## The convex hull decorator is a scene node decorator that adds the convex hull functionality to a scene node. -# If a scene node has a convex hull decorator, it will have a shadow in which other objects can not be printed. class ConvexHullDecorator(SceneNodeDecorator): + """The convex hull decorator is a scene node decorator that adds the convex hull functionality to a scene node. + + If a scene node has a convex hull decorator, it will have a shadow in which other objects can not be printed. + """ + def __init__(self) -> None: super().__init__() @@ -74,13 +77,16 @@ class ConvexHullDecorator(SceneNodeDecorator): self._onChanged() - ## Force that a new (empty) object is created upon copy. def __deepcopy__(self, memo): + """Force that a new (empty) object is created upon copy.""" + return ConvexHullDecorator() - ## The polygon representing the 2D adhesion area. - # If no adhesion is used, the regular convex hull is returned def getAdhesionArea(self) -> Optional[Polygon]: + """The polygon representing the 2D adhesion area. + + If no adhesion is used, the regular convex hull is returned + """ if self._node is None: return None @@ -90,9 +96,11 @@ class ConvexHullDecorator(SceneNodeDecorator): return self._add2DAdhesionMargin(hull) - ## Get the unmodified 2D projected convex hull of the node (if any) - # In case of one-at-a-time, this includes adhesion and head+fans clearance def getConvexHull(self) -> Optional[Polygon]: + """Get the unmodified 2D projected convex hull of the node (if any) + + In case of one-at-a-time, this includes adhesion and head+fans clearance + """ if self._node is None: return None if self._node.callDecoration("isNonPrintingMesh"): @@ -108,9 +116,11 @@ class ConvexHullDecorator(SceneNodeDecorator): return self._compute2DConvexHull() - ## For one at the time this is the convex hull of the node with the full head size - # In case of printing all at once this is None. def getConvexHullHeadFull(self) -> Optional[Polygon]: + """For one at the time this is the convex hull of the node with the full head size + + In case of printing all at once this is None. + """ if self._node is None: return None @@ -126,10 +136,12 @@ class ConvexHullDecorator(SceneNodeDecorator): return False return bool(parent.callDecoration("isGroup")) - ## Get convex hull of the object + head size - # In case of printing all at once this is None. - # For one at the time this is area with intersection of mirrored head def getConvexHullHead(self) -> Optional[Polygon]: + """Get convex hull of the object + head size + + In case of printing all at once this is None. + For one at the time this is area with intersection of mirrored head + """ if self._node is None: return None if self._node.callDecoration("isNonPrintingMesh"): @@ -142,10 +154,12 @@ class ConvexHullDecorator(SceneNodeDecorator): return head_with_fans_with_adhesion_margin return None - ## Get convex hull of the node - # In case of printing all at once this None?? - # For one at the time this is the area without the head. def getConvexHullBoundary(self) -> Optional[Polygon]: + """Get convex hull of the node + + In case of printing all at once this None?? + For one at the time this is the area without the head. + """ if self._node is None: return None @@ -157,10 +171,12 @@ class ConvexHullDecorator(SceneNodeDecorator): return self._compute2DConvexHull() return None - ## Get the buildplate polygon where will be printed - # In case of printing all at once this is the same as convex hull (no individual adhesion) - # For one at the time this includes the adhesion area def getPrintingArea(self) -> Optional[Polygon]: + """Get the buildplate polygon where will be printed + + In case of printing all at once this is the same as convex hull (no individual adhesion) + For one at the time this includes the adhesion area + """ if self._isSingularOneAtATimeNode(): # In one-at-a-time mode, every printed object gets it's own adhesion printing_area = self.getAdhesionArea() @@ -168,8 +184,9 @@ class ConvexHullDecorator(SceneNodeDecorator): printing_area = self.getConvexHull() return printing_area - ## The same as recomputeConvexHull, but using a timer if it was set. def recomputeConvexHullDelayed(self) -> None: + """The same as recomputeConvexHull, but using a timer if it was set.""" + if self._recompute_convex_hull_timer is not None: self._recompute_convex_hull_timer.start() else: @@ -325,9 +342,11 @@ class ConvexHullDecorator(SceneNodeDecorator): return convex_hull.getMinkowskiHull(head_and_fans) return None - ## Compensate given 2D polygon with adhesion margin - # \return 2D polygon with added margin def _add2DAdhesionMargin(self, poly: Polygon) -> Polygon: + """Compensate given 2D polygon with adhesion margin + + :return: 2D polygon with added margin + """ if not self._global_stack: return Polygon() # Compensate for raft/skirt/brim @@ -358,12 +377,14 @@ class ConvexHullDecorator(SceneNodeDecorator): poly = poly.getMinkowskiHull(extra_margin_polygon) return poly - ## Offset the convex hull with settings that influence the collision area. - # - # \param convex_hull Polygon of the original convex hull. - # \return New Polygon instance that is offset with everything that - # influences the collision area. def _offsetHull(self, convex_hull: Polygon) -> Polygon: + """Offset the convex hull with settings that influence the collision area. + + :param convex_hull: Polygon of the original convex hull. + :return: New Polygon instance that is offset with everything that + influences the collision area. + """ + horizontal_expansion = max( self._getSettingProperty("xy_offset", "value"), self._getSettingProperty("xy_offset_layer_0", "value") @@ -409,8 +430,9 @@ class ConvexHullDecorator(SceneNodeDecorator): self._onChanged() - ## Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property). def _getSettingProperty(self, setting_key: str, prop: str = "value") -> Any: + """Private convenience function to get a setting from the correct extruder (as defined by limit_to_extruder property).""" + if self._global_stack is None or self._node is None: return None per_mesh_stack = self._node.callDecoration("getStack") @@ -430,16 +452,18 @@ 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. def __isDescendant(self, root: "SceneNode", node: Optional["SceneNode"]) -> bool: + """Returns True if node is a descendant or the same as the root node.""" + if node is None: return False if root is node: return True return self.__isDescendant(root, node.getParent()) - ## True if print_sequence is one_at_a_time and _node is not part of a group def _isSingularOneAtATimeNode(self) -> bool: + """True if print_sequence is one_at_a_time and _node is not part of a group""" + if self._node is None: return False return self._global_stack is not None \ @@ -450,7 +474,8 @@ class ConvexHullDecorator(SceneNodeDecorator): "adhesion_type", "raft_margin", "print_sequence", "skirt_gap", "skirt_line_count", "skirt_brim_line_width", "skirt_distance", "brim_line_count"] - ## Settings that change the convex hull. - # - # If these settings change, the convex hull should be recalculated. _influencing_settings = {"xy_offset", "xy_offset_layer_0", "mold_enabled", "mold_width", "anti_overhang_mesh", "infill_mesh", "cutting_mesh"} + """Settings that change the convex hull. + + If these settings change, the convex hull should be recalculated. + """ diff --git a/cura/Scene/ConvexHullNode.py b/cura/Scene/ConvexHullNode.py index da2713a522..cd0951cba6 100644 --- a/cura/Scene/ConvexHullNode.py +++ b/cura/Scene/ConvexHullNode.py @@ -18,11 +18,13 @@ if TYPE_CHECKING: class ConvexHullNode(SceneNode): shader = None # To prevent the shader from being re-built over and over again, only load it once. - ## Convex hull node is a special type of scene node that is used to display an area, to indicate the - # location an object uses on the buildplate. This area (or area's in case of one at a time printing) is - # then displayed as a transparent shadow. If the adhesion type is set to raft, the area is extruded - # to represent the raft as well. def __init__(self, node: SceneNode, hull: Optional[Polygon], thickness: float, parent: Optional[SceneNode] = None) -> None: + """Convex hull node is a special type of scene node that is used to display an area, to indicate the + + location an object uses on the buildplate. This area (or area's in case of one at a time printing) is + then displayed as a transparent shadow. If the adhesion type is set to raft, the area is extruded + to represent the raft as well. + """ super().__init__(parent) self.setCalculateBoundingBox(False) diff --git a/cura/Scene/CuraSceneController.py b/cura/Scene/CuraSceneController.py index 36d9e68c8f..2fd05db87a 100644 --- a/cura/Scene/CuraSceneController.py +++ b/cura/Scene/CuraSceneController.py @@ -72,9 +72,10 @@ class CuraSceneController(QObject): max_build_plate = max(build_plate_number, max_build_plate) return max_build_plate - ## Either select or deselect an item @pyqtSlot(int) def changeSelection(self, index): + """Either select or deselect an item""" + modifiers = QApplication.keyboardModifiers() ctrl_is_active = modifiers & Qt.ControlModifier shift_is_active = modifiers & Qt.ShiftModifier diff --git a/cura/Scene/CuraSceneNode.py b/cura/Scene/CuraSceneNode.py index eb609def5a..b9f2279414 100644 --- a/cura/Scene/CuraSceneNode.py +++ b/cura/Scene/CuraSceneNode.py @@ -15,9 +15,11 @@ 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): + """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. + """ 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: @@ -36,9 +38,11 @@ class CuraSceneNode(SceneNode): def isSelectable(self) -> bool: return super().isSelectable() and self.callDecoration("getBuildPlateNumber") == cura.CuraApplication.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) -> Optional[ExtruderStack]: + """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 + """ global_container_stack = Application.getInstance().getGlobalContainerStack() if global_container_stack is None: return None @@ -69,8 +73,9 @@ class CuraSceneNode(SceneNode): # This point should never be reached return None - ## Return the color of the material used to print this model def getDiffuseColor(self) -> List[float]: + """Return the color of the material used to print this model""" + printing_extruder = self.getPrintingExtruder() material_color = "#808080" # Fallback color @@ -86,8 +91,9 @@ class CuraSceneNode(SceneNode): 1.0 ] - ## Return if any area collides with the convex hull of this scene node def collidesWithAreas(self, areas: List[Polygon]) -> bool: + """Return if any area collides with the convex hull of this scene node""" + convex_hull = self.callDecoration("getPrintingArea") if convex_hull: if not convex_hull.isValid(): @@ -101,8 +107,9 @@ class CuraSceneNode(SceneNode): return True return False - ## Override of SceneNode._calculateAABB to exclude non-printing-meshes from bounding box def _calculateAABB(self) -> None: + """Override of SceneNode._calculateAABB to exclude non-printing-meshes from bounding box""" + self._aabb = None if self._mesh_data: self._aabb = self._mesh_data.getExtents(self.getWorldTransformation()) @@ -122,8 +129,9 @@ class CuraSceneNode(SceneNode): else: self._aabb = self._aabb + child.getBoundingBox() - ## Taken from SceneNode, but replaced SceneNode with CuraSceneNode def __deepcopy__(self, memo: Dict[int, object]) -> "CuraSceneNode": + """Taken from SceneNode, but replaced SceneNode with CuraSceneNode""" + copy = CuraSceneNode(no_setting_override = True) # Setting override will be added later copy.setTransformation(self.getLocalTransformation()) copy.setMeshData(self._mesh_data) diff --git a/cura/Scene/ZOffsetDecorator.py b/cura/Scene/ZOffsetDecorator.py index b35b17a412..1f1f5a9b1f 100644 --- a/cura/Scene/ZOffsetDecorator.py +++ b/cura/Scene/ZOffsetDecorator.py @@ -1,8 +1,9 @@ from UM.Scene.SceneNodeDecorator import SceneNodeDecorator -## A decorator that stores the amount an object has been moved below the platform. class ZOffsetDecorator(SceneNodeDecorator): + """A decorator that stores the amount an object has been moved below the platform.""" + def __init__(self) -> None: super().__init__() self._z_offset = 0. |