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

    Class State

    Represents the current state of the print job

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

    Index
    e: number = 0

    Current extruder position in millimeters, tracked by applyExtrusion and reset by G92

    extrusionWidth: number = undefined

    Width of extruded material, in millimeters, for paths created from here on, or undefined until slicer metadata announces one.

    Fed by ;WIDTH: comments (PrusaSlicer family) via the slicer metadata pipeline (see Job.beginCommand). Paths created while this is undefined carry no width of their own and fall back at render time to the global setting, then to the built-in 0.6.

    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, for paths created from here on, or undefined until slicer metadata announces one.

    Fed by ;HEIGHT: comments (PrusaSlicer family), which vary throughout a print when adaptive layer height is enabled. Paths created while this is undefined carry no height of their own and fall back at render time to the global setting, then to the built-in 0.2.

    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 in millimeters, or undefined until the axis is homed (G28)

    y: number = undefined

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

    z: number = undefined

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

    • 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'

    • 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.