コード例 #1
0
def to_svg_path(line_segment_chain: LineSegmentChain, transformation=None, color="black", 
                stroke_width="0.864583px", draw_arrows=False) -> ElementTree.Element:
    """
    A handy debugging function which converts the current line-chain to svg form

    :param line_segment_chain: The LineSegmentChain to the converted.
    :param transformation: A transformation to apply to every line before converting it.
    :param color: The path's color.
    :param stroke_width: The path's stroke width.
    :param stroke_width: Whether or not to draw arrows at the end of each segment. Requires placing the output of
    arrow_defs() in the document.
    """

    start = Vector(line_segment_chain.get(0).start.x, line_segment_chain.get(0).start.y)
    if transformation:
        start = transformation.apply_transformation(start)

    d = f"M{start.x} {start.y}"

    for line in line_segment_chain:
        end = Vector(line.end.x, line.end.y)
        if transformation:
            end = transformation.apply_transformation(end)
        d += f" L {end.x} {end.y}"

    style = f"fill:none;stroke:{color};stroke-width:{stroke_width};stroke-linecap:butt;stroke-linejoin:miter;stroke" \
            "-opacity:1 "

    path = ElementTree.Element("{%s}path" % svg_namespace)
    path.set("d", d)
    path.set("style", style)
    if draw_arrows:
        path.set("marker-mid", "url(#arrow-346)")

    return path
コード例 #2
0
    def append_line_chain(self, line_chain: LineSegmentChain):
        """
        Draws a LineSegmentChain by calling interface.linear_move() for each segment. The resulting code is appended to
        self.body
        """

        if line_chain.chain_size() == 0:
            warnings.warn("Attempted to parse empty LineChain")
            return []

        code = []

        start = line_chain.get(0).start

        # Don't turn off laser if the new start is at the current position
        if self.interface.position is None or abs(
                self.interface.position - start) > TOLERANCES["operation"]:
            code = [
                self.interface.laser_off(),
                self.interface.linear_move(z=self.movement_height),
                self.interface.set_movement_speed(self.movement_speed),
                self.interface.linear_move(start.x, start.y),
                self.interface.set_movement_speed(self.cutting_speed),
                self.interface.set_laser_power(1),
                self.interface.linear_move(z=self.cutting_height)
            ]

        for line in line_chain:
            code.append(self.interface.linear_move(line.end.x, line.end.y))

        self.body.extend(code)