vpype_gscrib.processor

Vector graphics preprocessing for G-code generation.

This module provides the core functionality and interface for processing and rendering vpype documents. It is used by the vpype_gscrib.renderer module to produce the G-Code programs.

class vpype_gscrib.processor.DocumentProcessor(renderer: DocumentRenderer)

Bases: object

Processes vector graphics documents by traversing their hierarchical structure and delegating operations to a renderer.

This class walks through a document’s hierarchical structure —layers, paths, and segments— calling the appropriate methods to process a document on a DocumentRenderer instance.

The traversal order is:

  1. Start document processing.

  2. Process each layer of the document.

  3. Process each path within a layer.

  4. Process each segment within a path.

  5. End document processing.

process(document: Document)

Process a document by iterating through its layers.

class vpype_gscrib.processor.DocumentRenderer

Bases: ABC

Abstract base class defining the interface for document renderers.

This class defines a structured approach to processing a document by traversing its hierarchy: Document → Layers → Paths → Segments. Implementations of this class must provide methods to handle each stage of the traversal.

abstractmethod begin_document(document: Document)

This method is invoked once per document before any of the document layers are processed.

abstractmethod begin_layer(layer: LineCollection)

Each layer is composed of one or more paths. This method is invoked once per layer before any paths are processed.

abstractmethod begin_path(path: array)

Each path is composed of one or more segments. This method is invoked once per path before any of its segments are processed.

abstractmethod end_document(document: Document)

This method is invoked once per document after all layers on the document have been processed.

abstractmethod end_layer(layer: LineCollection)

This method is invoked once per layer after all paths on the layer have been processed.

abstractmethod end_path(path: array)

This method is invoked once per path after all segments of the path have been processed.

abstractmethod process_error(e: Exception)

Invoked if an error occurs during the processing of a document.

abstractmethod trace_segment(path: array, x: float, y: float)

This method is called once per segment within a path, receiving the segment’s x and y coordinates.