Exemple #1
0
    def run(self):
        """Main entry point for Inkscape extensions.
        """
        geom.debug.set_svg_context(self.svg)
        self.bezier_layer = self.svg.create_layer(self._LAYER_NAME)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return
        # Convert SVG elements to path geometry
        path_list = geomsvg.svg_to_geometry(svg_elements)

        self.svg.set_default_parent(self.bezier_layer)
        if self.options.draw_controlpoints:
            self.controlpoint_layer = self.svg.create_layer('control points')
        if self.options.draw_inflections or self.options.draw_subdivide_inflections:
            self.inflection_layer = self.svg.create_layer('inflections')
        if self.options.draw_normals:
            self.normals_layer = self.svg.create_layer('normals')
        if self.options.draw_biarcs:
            self.biarc_layer = self.svg.create_layer('biarcs')
        for path in path_list:
            for segment in path:
                if isinstance(segment, bezier.CubicBezier):
                    self.draw_curve_attributes(segment)
                if isinstance(segment, arc.Arc):
                    self.test_arcbez(segment)
Exemple #2
0
    def run(self):
        """Main entry point for Inkscape extensions.
        """
        geom.debug.set_svg_context(self.svg)
        self.bezier_layer = self.svg.create_layer(self._LAYER_NAME)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return
        # Convert SVG elements to path geometry
        path_list = geomsvg.svg_to_geometry(svg_elements)

        self.svg.set_default_parent(self.bezier_layer)
        if self.options.draw_controlpoints:
            self.controlpoint_layer = self.svg.create_layer('control points')
        if self.options.draw_inflections or self.options.draw_subdivide_inflections:
            self.inflection_layer = self.svg.create_layer('inflections')
        if self.options.draw_normals:
            self.normals_layer = self.svg.create_layer('normals')
        if self.options.draw_biarcs:
            self.biarc_layer = self.svg.create_layer('biarcs')
        for path in path_list:
            for segment in path:
                if isinstance(segment, bezier.CubicBezier):
                    self.draw_curve_attributes(segment)
                if isinstance(segment, arc.Arc):
                    self.test_arcbez(segment)
Exemple #3
0
    def run(self):
        """Main entry point for Inkscape extension.
        """
        random.seed()

        geom.set_epsilon(self.options.epsilon)
        geom.debug.set_svg_context(self.debug_svg)

        styles = self.svg.styles_from_templates(self._styles,
                                                self._style_defaults,
                                                self.options.__dict__)
        self._styles.update(styles)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return
        path_list = geomsvg.svg_to_geometry(svg_elements)

        # Path list should only have two sort of parallel paths
        if len(path_list) != 2:
            self.errormsg(_('Please select two polylines'))
            exit(1)

        layer = self.svg.create_layer('q_polylines', incr_suffix=True)
#        seglayer = self.svg.create_layer('q_segments', incr_suffix=True)
        segments = self._get_segments(path_list[0], path_list[1])

        if segments:
            self._draw_segments(segments)
            polylines = self._get_polylines(path_list[0], path_list[1], segments)
            if polylines:
                self._draw_polylines(polylines, layer)
Exemple #4
0
    def run(self):
        """Main entry point for Inkscape extension.
        """
        # Initialize the debug SVG context for the geometry package
        geom.debug.set_svg_context(self.debug_svg)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if svg_elements:
            path_list = geomsvg.svg_to_geometry(svg_elements)
        else:
            # Nothing selected or document is empty
            path_list = ()
Exemple #5
0
    def run(self):
        """Main entry point for Inkscape extension.
        """
        # Initialize the debug SVG context for the geometry package
        geom.debug.set_svg_context(self.debug_svg)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if svg_elements:
            path_list = geomsvg.svg_to_geometry(svg_elements)
        else:
            # Nothing selected or document is empty
            path_list = ()
Exemple #6
0
    def run(self):
        """Main entry point for Inkscape extension.
        """
        random.seed()

        geom.set_epsilon(self.options.epsilon)
        geom.debug.set_svg_context(self.debug_svg)

        styles = self.svg.styles_from_templates(self._styles,
                                                self._style_defaults,
                                                self.options.__dict__)
        self._styles.update(styles)

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return
        path_list = geomsvg.svg_to_geometry(svg_elements)

        # Create graph from geometry
        segment_graph = planargraph.Graph()
        for path in path_list:
            for segment in path:
                segment_graph.add_edge(segment)

        self.clip_rect = geom.box.Box((0, 0), self.svg.get_document_size())

        if self.options.polysegpath_draw or self.options.polysegpath_longest:
            path_builder = planargraph.GraphPathBuilder(segment_graph)
            if self.options.polysegpath_draw:
                self._draw_polypaths(path_builder)
            if self.options.polysegpath_longest:
                self._draw_longest_polypaths(path_builder)

        if self.options.polyoffset_draw:
            self._draw_offset_polygons(segment_graph)

        if self.options.convex_hull_draw:
            self._draw_convex_hull(segment_graph)

        if self.options.hull_draw:
            outer_hull = segment_graph.boundary_polygon()
            self._draw_polygon_hulls((outer_hull,))
            if self.options.hull_inner_draw:
                inner_hulls = segment_graph.peel_boundary_polygon(outer_hull)
                if inner_hulls:
                    self._draw_polygon_hulls(inner_hulls)
Exemple #7
0
    def run(self):
        """Main entry point for Inkscape plugins.
        """
        geom.set_epsilon(_GEOM_EPSILON)
        geom.debug.set_svg_context(self.debug_svg)

        self._styles.update(
            self.svg.styles_from_templates(self._styles, self._STYLE_DEFAULTS,
                                           self.options.__dict__))

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return

        # Convert the SVG elements to segment geometry
        path_list = geomsvg.svg_to_geometry(svg_elements)

        # Create a set of input points from the segment end points
        input_points = set()
        polygon_segment_graph = planargraph.Graph()
        for path in path_list:
            for segment in path:
                input_points.add(segment.p1)
                input_points.add(segment.p2)
                polygon_segment_graph.add_edge(segment)

        self.clip_rect = geom.box.Box((0, 0), self.svg.get_document_size())

        clipping_hull = None
        if self.options.clip_to_polygon:
            clipping_hull = polygon_segment_graph.boundary_polygon()

        voronoi_diagram = voronoi.VoronoiDiagram(
            list(input_points),
            do_delaunay=True,
            jiggle_points=self.options.jiggle_points)

        self._draw_voronoi(voronoi_diagram, clipping_hull)
Exemple #8
0
    def run(self):
        """Main entry point for Inkscape plugins.
        """
        geom.set_epsilon(_GEOM_EPSILON)
        geom.debug.set_svg_context(self.debug_svg)

        self._styles.update(self.svg.styles_from_templates(self._styles,
                                                          self._STYLE_DEFAULTS,
                                                          self.options.__dict__))

        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements())
        if not svg_elements:
            # Nothing selected or document is empty
            return

        # Convert the SVG elements to segment geometry
        path_list = geomsvg.svg_to_geometry(svg_elements)

        # Create a set of input points from the segment end points
        input_points = set()
        polygon_segment_graph = planargraph.Graph()
        for path in path_list:
            for segment in path:
                input_points.add(segment.p1)
                input_points.add(segment.p2)
                polygon_segment_graph.add_edge(segment)

        self.clip_rect = geom.box.Box((0,0), self.svg.get_document_size())

        clipping_hull = None
        if self.options.clip_to_polygon:
            clipping_hull = polygon_segment_graph.boundary_polygon()

        voronoi_diagram = voronoi.VoronoiDiagram(
            list(input_points), do_delaunay=True,
            jiggle_points=self.options.jiggle_points)

        self._draw_voronoi(voronoi_diagram, clipping_hull)
Exemple #9
0
    def run(self):
        """Main entry point for Inkscape plugins.
        """
        # Initialize the geometry module with tolerances and debug output
        geom.set_epsilon(self.options.tolerance)
        geom.debug.set_svg_context(self.debug_svg)

        # Create a transform to flip the Y axis.
        page_height = self.svg.get_document_size()[1]
        flip_transform = transform2d.matrix_scale_translate(
            1.0, -1.0, 0.0, page_height)
        timer_start = timeit.default_timer()
        #        skip_layers = (gcodesvg.SVGPreviewPlotter.PATH_LAYER_NAME,
        #                       gcodesvg.SVGPreviewPlotter.TOOL_LAYER_NAME)
        skip_layers = ['tcnc .*']
        # Get a list of selected SVG shape elements and their transforms
        svg_elements = self.svg.get_shape_elements(self.get_elements(),
                                                   skip_layers=skip_layers)
        if not svg_elements:
            # Nothing selected or document is empty
            return
        # Convert SVG elements to path geometry
        path_list = geomsvg.svg_to_geometry(svg_elements, flip_transform)
        # Create the output file path name
        filepath = create_pathname(self.options.output_path,
                                   append_suffix=self.options.append_suffix)
        try:
            with io.open(filepath, 'w') as output:
                gcgen = self._init_gcode(output)
                cam = self._init_cam(gcgen)
                cam.generate_gcode(path_list)
        except IOError as error:
            self.errormsg(str(error))
        timer_end = timeit.default_timer()
        total_time = timer_end - timer_start
        logger.info('Tcnc time: %s', str(timedelta(seconds=total_time)))