コード例 #1
0
    def append_curves(self, curves: [typing.Type[Curve]]):
        """
        Draws curves by approximating them as line segments and calling self.append_line_chain(). The resulting code is
        appended to self.body
        """

        for curve in curves:
            line_chain = LineSegmentChain()

            approximation = LineSegmentChain.line_segment_approximation(curve)

            line_chain.extend(approximation)

            self.append_line_chain(line_chain)
コード例 #2
0
def run_test(svg_file_name, debug_file_name):
    curves = parse_file(svg_file_name)

    success = True
    approximations = []
    count = 0
    for curve in curves:
        approximation = LineSegmentChain.line_segment_approximation(curve)
        approximations.append(approximation)
        count += approximation.chain_size()

    generate_debug(approximations, svg_file_name, debug_file_name)

    return success
コード例 #3
0
def run_test(svg_file_name, debug_file_name):
    curves = parse_file(svg_file_name)

    success = True
    approximations = []
    for curve in curves:
        approximation = LineSegmentChain.line_segment_approximation(curve)
        approximations.append(approximation)

        # Todo find a way to automatically determine success. Right now manual revision of debug files is required.

    generate_debug(approximations, svg_file_name, debug_file_name)

    return success
コード例 #4
0
    def draw_debug_traces(self, curves):
        """Traces arrows over all parsed paths"""

        root = self.document.getroot()
        origin = self.options.machine_origin
        bed_width = self.options.bed_width
        bed_height = self.options.bed_height

        height_str = root.get("height")
        canvas_height = float(height_str) if height_str.isnumeric() else float(
            height_str[:-2])

        group = etree.Element("{%s}g" % svg_name_space)
        group.set("id", "debug_traces")
        group.set("{%s}groupmode" % inkscape_name_space, "layer")
        group.set("{%s}label" % inkscape_name_space, "debug traces")

        group.append(
            etree.fromstring(
                xml_tree.tostring(
                    debug_methods.arrow_defs(
                        arrow_scale=self.options.debug_arrow_scale))))

        for curve in curves:
            approximation = LineSegmentChain.line_segment_approximation(curve)

            change_origin = Transformation()

            if origin != "top-left":
                change_origin.add_scale(1, -1)
                change_origin.add_translation(0, -canvas_height)

            if origin == "center":
                change_origin.add_translation(bed_width / 2, bed_height / 2)

            path_string = xml_tree.tostring(
                debug_methods.to_svg_path(
                    approximation,
                    color="red",
                    stroke_width=f"{self.options.debug_line_width}px",
                    transformation=change_origin,
                    draw_arrows=True))

            group.append(etree.fromstring(path_string))

        root.append(group)