knitout_to_dat_python.dat_file_structure.raster_carriage_passes.Raster_Carriage_Pass module

Raster_Pass class that wraps Carriage_Pass to extract DAT file generation information.

This module provides the Raster_Carriage_Pass class, which wraps Carriage_Pass objects to extract information needed for DAT raster generation. It converts knitout operations into colored pixels and option line settings based on the original knitout-to-dat.js raster generation logic.

class Raster_Carriage_Pass(carriage_pass: Carriage_Pass, machine_specification: Knitting_Machine_Specification, min_knitting_slot: int, max_knitting_slot: int, hook_operation: Hook_Operation_Color = Hook_Operation_Color.No_Hook_Operation, stitch_number: int = 5, speed_number: int = 0, presser_setting: Presser_Setting_Color = Presser_Setting_Color.Off, pause: bool = False, knit_cancel: Knit_Cancel_Color = Knit_Cancel_Color.Standard, drop_sinker: bool = False)[source]

Bases: object

Wrapper for Carriage_Pass that extracts information needed for DAT raster generation.

This class converts knitout operations into colored pixels and option line settings that can be used to generate DAT file raster data. It processes carriage pass instructions and machine settings to create the appropriate pixel representation.

Parameters:
  • carriage_pass (Carriage_Pass)

  • machine_specification (Knitting_Machine_Specification)

  • min_knitting_slot (int)

  • max_knitting_slot (int)

  • hook_operation (Hook_Operation_Color, default: Hook_Operation_Color.No_Hook_Operation)

  • stitch_number (int, default: 5)

  • speed_number (int, default: 0)

  • presser_setting (Presser_Setting_Color, default: Presser_Setting_Color.Off)

  • pause (bool, default: False)

  • knit_cancel (Knit_Cancel_Color, default: Knit_Cancel_Color.Standard)

  • drop_sinker (bool, default: False)

__init__(carriage_pass: Carriage_Pass, machine_specification: Knitting_Machine_Specification, min_knitting_slot: int, max_knitting_slot: int, hook_operation: Hook_Operation_Color = Hook_Operation_Color.No_Hook_Operation, stitch_number: int = 5, speed_number: int = 0, presser_setting: Presser_Setting_Color = Presser_Setting_Color.Off, pause: bool = False, knit_cancel: Knit_Cancel_Color = Knit_Cancel_Color.Standard, drop_sinker: bool = False)[source]

Initialize a Raster_Pass from a Carriage_Pass.

Parameters:
  • carriage_pass (Carriage_Pass) – The carriage pass to wrap.

  • machine_specification (Knitting_Machine_Specification) – The machine specification for the knitout file specified in the knitout header.

  • min_knitting_slot (int) – The minimum slot of knitting operations in this file.

  • max_knitting_slot (int) – The maximum slot of knitting operations in this file.

  • hook_operation (Hook_Operation_Color, optional) – The operation of the yarn-inserting hook for this carrier. Defaults to Hook_Operation_Color.No_Hook_Operation.

  • stitch_number (int, optional) – Current stitch setting. Defaults to 5.

  • speed_number (int, optional) – Current speed setting. Defaults to 0.

  • presser_setting (Presser_Setting_Color, optional) – Current presser mode (‘on’, ‘off’, ‘auto’). Defaults to Presser_Setting_Color.Off.

  • pause (bool, optional) – Whether this pass should pause. Defaults to False.

  • knit_cancel (Knit_Cancel_Color, optional) – Knit cancel mode setting. Will be reset to true for transfer carriage passes. Defaults to Knit_Cancel_Color.Standard.

  • drop_sinker (bool, optional) – Set to true to set “drop failure, sinker reset”. Defaults to False.

Raises:

AssertionError – If inhook operation is attempted on a rightward knitting pass.

drop_sinker: bool

Whether drop sinker mode is enabled.

Type:

bool

carriage_pass: Carriage_Pass

The wrapped carriage pass object.

Type:

Carriage_Pass

max_knitting_slot: int

The maximum slot of knitting operations in this file.

Type:

int

min_knitting_slot: int

The minimum slot of knitting operations in this file.

Type:

int

machine_specification: Knitting_Machine_Specification

The machine specification for the knitout file.

Type:

Knitting_Machine_Specification

stitch_number: int

Current stitch setting.

Type:

int

speed_number: int

Current speed setting.

Type:

int

presser_setting: Presser_Setting_Color

Current presser mode setting.

Type:

Presser_Setting_Color

slot_colors: dict[int, Operation_Color]

Dictionary mapping slot numbers to their operation color codes.

Type:

dict[int, Operation_Color]

left_option_line_settings: dict[Left_Option_Lines, int]

Dictionary of left option line settings.

Type:

dict[Left_Option_Lines, int]

right_option_line_settings: dict[Right_Option_Lines, int]

Dictionary of right option line settings.

Type:

dict[Right_Option_Lines, int]

property knit_cancel: Knit_Cancel_Color

Get the value of the knit-cancel option.

Returns:

Value of the knit-cancel option.

Return type:

Knit_Cancel_Color

shift_slot_colors(shift: int) None[source]

Shift the slot numbers of the carriage pass by the given amount.

Parameters:

shift (int) – The amount to shift the slots by.

Return type:

None

property hook_operation: Hook_Operation_Color

Get the hook operation for the given carriage pass.

Returns:

The Hook operation for the given carriage pass.

Return type:

Hook_Operation_Color

property empty_pass: bool

Check if there are no needle operations in this carriage pass.

Returns:

True if there are no needle operations in this carriage pass.

Return type:

bool

property min_slot: int | None

Get the leftmost slot that operations will occur on.

Returns:

None if there are no needle operations in this carriage pass. Otherwise, return the leftmost slot that operations will occur on.

Return type:

int | None

property max_slot: int | None

Get the rightmost slot that operations will occur on.

Returns:

None if there are no needle operations in this carriage pass. Otherwise, return the rightmost slot that operations will occur on.

Return type:

int | None

property has_splits: bool

Check if the carriage pass has split operations.

Returns:

True if the carriage pass has splits. False otherwise.

Return type:

bool

property pause: bool

Check if this carriage pass will have a pause option.

Returns:

True if this carriage pass will have a pause option.

Return type:

bool

property direction_color: Carriage_Pass_Direction_Color

Get the direction color for this raster Carriage Pass.

Returns:

The direction color of for this raster Carriage Pass.

Return type:

Carriage_Pass_Direction_Color

get_slot_range() tuple[int, int][source]

Get the range of slots this pass operates on.

Returns:

The range of slots this pass operates on. Returns (0, 0) for empty passes.

Return type:

tuple[int, int]

static raster_width(pattern_width: int, option_space: int = 10, pattern_space: int = 4) int[source]

Calculate the expected width of a raster row.

Parameters:
  • pattern_width (int) – Width of the knitting pattern.

  • option_space (int, optional) – Spacing around the exterior of the option lines. Defaults to 10.

  • pattern_space (int, optional) – Spacing between option lines and the knitting pattern. Defaults to 4.

Returns:

The expected width of a raster row with the given width parameters.

Return type:

int

get_raster_row(pattern_width: int, option_space: int = 10, pattern_space: int = 4, offset_slots: int = 0) list[int][source]

Generate the complete raster row for this carriage pass.

Creates the full pixel representation of this carriage pass including left option lines, needle operations, and right option lines.

Parameters:
  • pattern_width (int) – The width of the knitting pattern.

  • option_space (int, optional) – The spacing around the option lines. Defaults to 10.

  • pattern_space (int, optional) – The spacing between option lines and the pattern. Defaults to 4.

  • offset_slots (int, optional) – The amount to offset the slots. Used in patterns with no 0-needles, to offset everything 1 to left (-1 offset). Defaults to 0.

Returns:

The list of color-codes that correspond to a row of the DAT raster for the given carriage pass.

Return type:

list[int]

Raises:

AssertionError – If the generated raster row length doesn’t match the expected width.

static get_option_margin_width(option_buffer: int = 10) int[source]

Calculate the width of the option line margin.

Parameters:

option_buffer (int, optional) – The amount of padding outside the option lines. Defaults to 10.

Returns:

The number of pixels of the option line margin width up to the beginning of the pattern’s buffer.

Return type:

int

__str__() str[source]

Return string representation of the raster pass.

Returns:

String representation showing slot range, direction, carriers, and operation count.

Return type:

str