gcode-preview - v3.0.0-alpha.5
    Preparing search index...

    Class State

    Represents the current state of the print job

    Tracks the current position, extrusion state, active tool, and units

    Index

    Constructors

    Properties

    e: number = 0

    Current extruder position, tracked by applyExtrusion and reset by G92

    extrusionWidth: number = undefined

    Width of extruded material, in millimeters, as announced by the slicer, or undefined while no comment has announced one.

    Fed by ;WIDTH: comments (PrusaSlicer family) via the slicer metadata pipeline (see Job.beginCommand). An announced width outranks both the one the caller supplied and the one derived from the moves: the slicer states what it asked the printer for, while the derivation infers it. The Job resolves that order when it starts a path.

    isHomed: boolean = false

    Whether the axes have been homed (G28).

    Until an axis is homed its real position is unknown, which is why x/y/z can be undefined. Consumers can read this flag to tell real coordinates from ones a renderer may have assumed. How to render an un-homed position is the job's decision (see Job.resolvePosition), not the state's.

    lineHeight: number = undefined

    Height of the extruded line, in millimeters, as announced by the slicer, or undefined while no comment has announced one.

    Fed by ;HEIGHT: comments (PrusaSlicer family), which vary throughout a print when adaptive layer height is enabled. Outranks the supplied and derived heights for the same reason as extrusionWidth.

    positionShift: { x: number; y: number; z: number } = ...

    Shift between the logical G-code coordinates and the physical position, created by G92: physical = logical + positionShift.

    G92 gives the current position new coordinates without moving the printhead. The state keeps tracking the physical position in x/y/z, so move handlers add this shift to incoming X/Y/Z parameters to translate them back into physical space. Mirrors Marlin's position_shift, and is kept separate from future home offsets (M206/M428) so the two can compose. E is deliberately not part of the shift: as in Marlin, G92 E sets the extruder position (e) directly.

    relativeExtrusion: boolean = false

    Whether E parameters are relative distances (M83) rather than absolute extruder positions (M82).

    Defaults to absolute, matching every major firmware (Marlin, Klipper, RepRapFirmware, Smoothieware). A file that uses relative E without saying so reads as one long retraction and renders as travel moves only. Slicers always emit M82 or M83, so that only affects hand-written gcode -- and guessing the other way would misread the declared-absolute files this exists to get right.

    tool: number = 0

    Currently active tool

    units: Units = 'mm'

    Current units (millimeters or inches)

    x: number = undefined

    Current X position, or undefined until the axis is homed (G28)

    y: number = undefined

    Current Y position, or undefined until the axis is homed (G28)

    z: number = undefined

    Current Z position, or undefined until the axis is homed (G28)

    Accessors

    • get initial(): State

      Gets a new State instance with default initial values

      Returns State

      New State with an un-homed (unknown) position, e=0, tool=0, units='mm'

    Methods

    • Applies a move's E parameter to the extruder position

      Parameters

      • e: number

        The move's E parameter, or undefined when the move has none

      Returns number

      The filament length this move extrudes (negative for retractions)

      In relative mode (M83) the parameter is the extruded length itself; in absolute mode (M82) the length is the difference with the tracked position. Both modes leave e at the move's resulting extruder position, so G92 E resets (which set e directly) compose naturally with either.