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 Gauged_Sheet_Record(gauge, knitting_machine)[source]
Bases:
object
Class 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:
Knitting_Machine
- Parameters:
gauge (
int
)knitting_machine (
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.
- Return type:
- peel_sheet_relative_to_active_sheet(active_sheet)[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 (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_Line]: 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:
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_Line]
- 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]
Get the layer index of loops held on the needles at the given needle position.
Returns the current layer assignment for the specified needle position. Layer indices range from 0 (front) to gauge-1 (back), representing the relative depth of the needle in the sheet configuration.
- sheet_needles_at_needle_position(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.
- Parameters:
needle_pos (int | Needle) – The position of the sheet needles needed. Accepts an integer in real needle positions, a needle, or a sheet needle.
- Returns:
A list of sheet needles in the order of the sheets with needles at the same relative position as needle_pos.
- Return type:
list[Sheet_Needle]
- set_layer_position(needle_pos, layer_value, push_forward=True, push_backward=False, swap=False)[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 | Needle) – The position of the needle to set the layer of. Accepts an integer or a needle.
layer_value (int) – The position to set the layer to. Lower values are brought forward. Must be in range 0 to gauge-1.
push_forward (bool, optional) – If True, rotates sheet needle layers forward until this needle has the target layer value. Defaults to True.
push_backward (bool, optional) – If True, rotates sheet needle layers backward until this needle has the target layer value. Defaults to False.
swap (bool, optional) – If True, swap layer values with the needle that currently has the target layer value. Defaults to False.
- Return type:
Note
Exactly one of push_forward, push_backward, or swap must be True. The method determines how other needles are reorganized when this needle is moved to the target layer.
- 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:
- Return type:
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:
needle_position (int | Needle) – A needle position to rotate layer values from. Integers and Needles are considered in the actual machine space. Sheet needles will be relative to other sheets.
pushed_layers (int, optional) – Amount to move backward, circles around from 0 to back layer. Defaults to 1.
- Return type:
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:
needle_position (int) – A needle position to rotate layer values from. Integers and Needles are considered in the actual machine space. Sheet needles will be relative to other sheets.
pushed_layers (int, optional) – Amount to move forward, circles around from back layer to front layer. Defaults to 1.
- Return type:
Note
This method is equivalent to push_layer_backward with a negated pushed_layers value.
- set_layer_to_front(needle_position, push_forward=True, push_backward=False, swap=False)[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.
push_forward (bool, optional) – If True, rotates sheet needle layers forward until this needle has the target layer value. Defaults to True.
push_backward (bool, optional) – If True, rotates sheet needle layers backward until this needle has the target layer value. Defaults to False.
swap (bool, optional) – If True, swap layer values with the needle that currently has the target layer value. Defaults to False.
- Return type:
- set_layer_to_back(needle_position, push_forward=True, push_backward=False, swap=False)[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.
push_forward (bool, optional) – If True, rotates sheet needle layers forward until this needle has the target layer value. Defaults to True.
push_backward (bool, optional) – If True, rotates sheet needle layers backward until this needle has the target layer value. Defaults to False.
swap (bool, optional) – If True, swap layer values with the needle that currently has the target layer value. Defaults to False.
- Return type:
- 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.