knit_script.knit_script_interpreter.scope.gauged_sheet_schema.Gauged_Sheet_Record module
Module containing the Gauged_Sheet_Record class and Sheet class.
This module provides functionality for managing sheet-based needle organization in knitting machines with gauged configurations. The Gauged_Sheet_Record class maintains state tracking for multiple sheets at different layers and provides methods for organizing, peeling, and resetting needle positions across sheets.
The module handles complex operations like sheet peeling, layer management, and loop state tracking across multiple gauge configurations.
- class Layer_Swap_Type(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]
Bases:
EnumEnumeration of layer swapping schemas.
- swap = 'Swap'
- push_forward = 'Push Forward'
- push_backward = 'Push Backward'
- classmethod __contains__(member)
Return True if member is a member of this enum raises TypeError if member is not an enum member
note: in 3.12 TypeError will no longer be raised, and True will also be returned if member is the value of a member in this enum
- classmethod __getitem__(name)
Return the member matching name.
- classmethod __iter__()
Return members in definition order.
- classmethod __len__()
Return the number of members (no aliases)
- class Gauged_Sheet_Record(gauge, knitting_machine)[source]
Bases:
objectClass for maintaining a record of loops on each sheet at the current gauging schema.
The Gauged_Sheet_Record manages the organization of knitting machine needles across multiple sheets in a gauged configuration. It tracks loop states, handles sheet peeling operations, and manages layer positioning for complex knitting patterns that require multiple working levels.
This class is essential for advanced knitting techniques that involve working with multiple sheets of fabric simultaneously, such as double-knit fabrics or complex color-work patterns.
- knitting_machine
The knitting machine being managed.
- Type:
Knitout_Knitting_Machine
- __init__(gauge, knitting_machine)[source]
Initialize the gauged sheet record with specified gauge and machine.
Creates a new gauged sheet record that manages needle organization across multiple sheets based on the specified gauge value. Each sheet corresponds to a different layer in the gauge configuration.
- Parameters:
gauge (int) – The gauge value determining the number of sheets to create. Must be a positive integer representing the number of working levels.
knitting_machine (Knitting_Machine) – The knitting machine instance that this record will manage. The machine provides needle access and state information.
- record_needle(needle)[source]
Record the state of the given needle assuming it is not moved for sheets.
Updates the internal record with the current state of the specified needle. If the needle is not already a Sheet_Needle, it will be converted to one based on the current gauge configuration.
- Parameters:
needle (Needle) – The needle to record the state of. Can be any type of needle, which will be converted to a Sheet_Needle if necessary.
- peel_sheet_relative_to_active_sheet(active_sheet_id)[source]
Move loops out of the way of the active sheet based on needle layer positions.
This method implements sheet peeling by moving loops that would interfere with the active sheet to appropriate positions. Loops are moved based on their layer relationships - loops in front of the active sheet on the back bed are moved, and loops behind the active sheet on the front bed are moved.
- Parameters:
active_sheet_id (int) – The sheet to activate by peeling all other needles based on their relative layers. Must be a valid sheet index within the gauge range.
- Returns:
A tuple containing: - list[Knitout_Comment_Line | Xfer_Instruction]: The knitout instructions that peel the layers, including transfer operations and comments. - list[int]: The needle positions that hold loops on the front or back beds in the same layer as the given active sheet.
- Return type:
tuple[list[Knitout_Comment_Line | Xfer_Instruction], list[int]]
Note
This operation is essential for complex multi-sheet knitting where different sheets need to be worked at different times without interference from loops on other sheets.
- reset_to_sheet(sheet_id)[source]
Return loops to a recorded location in a layer gauging schema.
This method restores the needle configuration to a previously recorded state for the specified sheet. It handles complex loop management including detecting lost loops, stacked loop conflicts, and blocked loop situations.
- Parameters:
sheet_id (int) – The sheet to reset to. Must be a valid sheet index within the gauge range.
- Returns:
The knitout instructions needed to reset to that sheet, including any necessary transfer operations and comments.
- Return type:
list[Knitout_Comment_Line | Xfer_Instruction]
- Raises:
Lost_Sheet_Loops_Exception – If loops that were recorded are no longer present on the expected needles.
Sheet_Peeling_Stacked_Loops_Exception – If stacked loops cannot be properly separated during the reset operation.
Sheet_Peeling_Blocked_Loops_Exception – If loops are blocked from returning to their expected positions due to conflicts.
Note
This operation is crucial for maintaining consistency when switching between different sheet configurations during complex knitting patterns.
- get_layer_at_position(needle_pos)[source]
- Parameters:
needle_pos (int | Needle_Specification) – The position of a needle to find the layer value for. If a needle is given, the position is extracted from the needle.
- Returns:
The layer index of loops held on the needles at the given needle position. Range 0 or greater and less than the current gauge.
- Return type:
Notes
Layer indices range from 0 (front) to gauge-1 (back), representing the relative depth of the needle in the sheet configuration.
- needles_at_same_position_in_sheets(needle_pos)[source]
Get a list of sheet needles in the order of the sheets with needles at the same relative position as needle_pos.
Returns all sheet needles that correspond to the same relative position across all sheets in the gauge configuration. This is useful for operations that need to work with corresponding needles across multiple sheets.
- set_layer_position(needle_pos, layer_value, layer_rotation_style=Layer_Swap_Type.push_forward)[source]
Set the layer at the given needle position to the given layer value.
Reorganizes needle layer assignments to place the specified needle at the target layer. Other needles at corresponding sheet positions are reorganized based on the specified method (forward rotation, backward rotation, or swapping).
- Parameters:
needle_pos (int) – The position of the needle to set the layer of.
layer_value (int) – The position to set the layer to. Lower values are brought forward. Must be in range 0 to gauge-1.
layer_rotation_style (Layer_Swap_Type, optional) – The schema for rotating layers (e.g., Swap, push forward, or push backward). Defaults to Layer_Swap_Type.push_forward.
- swap_layer_at_positions(position_a, position_b)[source]
Swap the layer values between two needle positions. Exchanges the layer assignments between two needle positions. This operation is useful for reorganizing sheet layers without affecting other needles.
- Parameters:
Note
The order of the needle positions does not affect the outcome. Both positions must be valid needle positions within the machine range.
- push_layer_backward(needle_position, pushed_layers=1)[source]
Change the layer positions of needles at the sheet positions relative to the given needle position.
Rotates the layer assignments at corresponding sheet positions by moving them backward by the specified number of layers. The rotation wraps around from the back layer (gauge-1) to the front layer (0).
- Parameters:
Note
A pushed_layers value of 0 results in no operation. Negative values will effectively push forward.
- push_layer_forward(needle_position, pushed_layers=1)[source]
Change the layer positions of needles at the sheet positions relative to the given needle position.
Rotates the layer assignments at corresponding sheet positions by moving them forward by the specified number of layers. This is implemented as a backward push with negated distance.
- Parameters:
Note
This method is equivalent to push_layer_backward with a negated pushed_layers value.
- set_layer_to_front(needle_position, layer_rotation_style=Layer_Swap_Type.push_forward)[source]
Set the layer as the front layer.
Convenience method to set the specified needle position to layer 0 (front). This is equivalent to calling set_layer_position with layer_value=0.
- Parameters:
needle_position (int) – The needle to set the layer to the front layer.
layer_rotation_style (Layer_Swap_Type, optional) – The schema for rotating layers (e.g., Swap, push forward, or push backward). Defaults to Layer_Swap_Type.push_forward.
- set_layer_to_back(needle_position, layer_rotation_style=Layer_Swap_Type.push_forward)[source]
Set the layer as the back layer.
Convenience method to set the specified needle position to the back layer (gauge-1). This is equivalent to calling set_layer_position with layer_value=gauge-1.
- Parameters:
needle_position (int) – The needle to set the layer to back layer.
layer_rotation_style (Layer_Swap_Type, optional) – The schema for rotating layers (e.g., Swap, push forward, or push backward). Defaults to Layer_Swap_Type.push_forward.
- front_needles(sheet)[source]
Get the set of front bed needles on the machine that belong to the given sheet.
- back_needles(sheet)[source]
Get the set of back bed needles on the machine that belong to the given sheet.
- front_sliders(sheet)[source]
Get the set of front bed slider needles on the machine that belong to the given sheet.
- back_sliders(sheet)[source]
Get the set of back bed slider needles on the machine that belong to the given sheet.
- front_loops(sheet)[source]
Get the list of front bed needles that belong to this sheet and currently hold loops.
- back_loops(sheet)[source]
Get the list of back bed needles that belong to this sheet and currently hold loops.
- front_slider_loops(sheet)[source]
Get the list of front bed slider needles that belong to this sheet and currently hold loops.
- back_slider_loops(sheet)[source]
Get the list of back bed slider needles that belong to this sheet and currently hold loops.
- all_needles(sheet)[source]
Get list of all needles on the sheet with front bed needles given first.
- all_sliders(sheet)[source]
Get list of all slider needles on the sheet with front bed sliders given first.
- all_loops(sheet)[source]
Get list of all loop-holding needles on the sheet with front bed needles given first.