knitout_interpreter.knitout_operations.Rack_Instruction module

Module for the Rack_Instruction class.

class Rack_Instruction(*args, **kwargs)[source]

Bases: Knitout_Instruction

Instruction for setting the rack alignment between front and back beds.

instruction_type: ClassVar[Knitout_Instruction_Type] = 'rack'
__init__(rack, comment=None)[source]

Initialize a rack instruction.

Parameters:
  • rack (float) – The rack value including all-needle alignment specification.

  • comment (None | str) – Optional comment to include with the instruction.

property rack: int

Get the integer value of rack alignment.

Returns:

Integer value of rack alignment.

property all_needle_rack: bool

Check if rack causes all-needle-knitting alignment.

Returns:

True if rack causes all-needle-knitting alignment.

property rack_value: float

Get the rack value including all-needle-knitting alignment.

Returns:

The value of the rack including all-needle-knitting alignment as float specification.

will_update_machine_state(machine_state)[source]
Parameters:

machine_state (Knitting_Machine) – The machine state to test if this instruction will update it.

Returns:

True if the rack set by this instruction differs from the current racking of the machine.

Return type:

bool

execute(machine_state)[source]

Execute the rack instruction on the given machine.

Parameters:

machine_state (Knitout_Knitting_Machine) – The knitting machine to update with the rack instruction.

Returns:

True if the machine state was updated, False if no change was needed.

Return type:

bool

static rack_instruction_from_int_specification(rack=0, all_needle_rack=False, comment=None)[source]

Create a rack instruction from integer specification.

Note: From Knitout Specification: Number indicating the offset of the front bed relative to the back bed. That is, at racking R, back needle index B is aligned to front needle index B+R. Needles are considered aligned if they can transfer. That is, at racking 2, it is possible to transfer from f3 to b1. May be fractional on some machines. E.g., on Shima machines, 0.25/-0.75 are used for all-needle knitting.

Parameters:
  • rack (int) – Integer racking value (default 0).

  • all_needle_rack (bool) – Whether to use all-needle knitting alignment (default False).

  • comment (None | str) – Optional comment to include with the instruction.

Returns:

Rack instruction configured with the specified parameters.

Return type:

Rack_Instruction

__str__()[source]

Return string representation of the rack instruction.

Returns:

String representation showing instruction type, rack value, and comment.

Return type:

str

__hash__()
Returns:

Unique integer based on the time that this instruction was created in the execution.

Return type:

int

classmethod __init_subclass__(**kwargs)

Automatically wrap execute() method in all subclasses.

static __new__(cls, *args, **kwargs)

Counts the number of knitout lines created while running a program. Ensures a unique identifier for each knitout line.

property comment_str: str

Get the comment as a formatted string.

Returns:

The comment formatted as a string with appropriate formatting.

property follow_comments: list[Knitout_Comment_Line]

Returns: list[Knitout_Comment_Line]: A list of Knitout_Comment_Line objects that follow this line.

property has_comment: bool

Check if this line has a comment.

Returns:

True if comment is present. False, otherwise.

Return type:

bool

property has_line_number: bool

Returns: bool: True if the original line number of this knitout line has been set.

id_str()

Get string representation with original line number if present.

Returns:

String with original line number added if present.

Return type:

str

interrupts_carriage_pass: ClassVar[bool] = True
property line_number: int

Returns: int: The current position of the line in a program.

property original_line_number: int

Returns: int: The original position of this line from the program it was parsed from.

set_line(line_number, source=None)

Set the line number of this instruction. If this is the first time that the instruction’s line was set, the value will become the original line number.

Parameters:
  • line_number (int) – The line number of this knitout instruction in a program.

  • source (str, optional) – The optional program name that this line derives from. This value is only set once (usually when setting the original line number). Defaults to None, not setting the program value.

property source_program: str | None

Returns: str | None: The name of the program this was parsed from or None if that value is unknown.

comment: str | None