gcode_reader.emulate.operations

Classes

AdditiveOperation

An Operation specialized for additive processes (e.g., 3D printing).

AdditiveProcessData

Stores ProcessData associated with Command execution by a Machine for an additive operation.

Operation

Represents a single manufacturing step.

ProcessData

Stores data associated with Command execution by a Machine.

ProcessDataArrays

Columnar (struct-of-arrays) view of a List[ProcessData].

SubtractiveOperation

An Operation specialized for subtractive processes (e.g., milling, CNC).

SubtractiveProcessData

Stores process_data associated with Command execution by a Machine for a subtractive operation.

Functions

make_process_data(→ ProcessData)

Return a fresh ProcessData instance appropriate for operation_cls.

register_process_data(→ None)

Associate an Operation subclass with the ProcessData subclass it produces.

Module Contents

class gcode_reader.emulate.operations.AdditiveOperation[source]

Bases: Operation

An Operation specialized for additive processes (e.g., 3D printing).

class gcode_reader.emulate.operations.AdditiveProcessData[source]

Bases: ProcessData

Stores ProcessData associated with Command execution by a Machine for an additive operation.

bead_area: float = None
deposited_volume: float = 0.0
extruder_type: type = None
class gcode_reader.emulate.operations.Operation[source]

Represents a single manufacturing step.

Holds sequence of commands and stores the resulting process data after simulation or execution by a machine model.

name

A human-readable name for the operation.

commands

A list of Command objects that define the machine’s actions.

process_data

A list of ProcessData objects, populated after processing, containing detailed information like tool locations and timing.

processed_by_machine

Stores the type of the machine that last processed this operation.

get_all_locations() numpy.ndarray[source]

Gathers all valid (non-None) location coordinates from the process data.

Returns:

A NumPy array of shape (N, 3) containing the [x, y, z] coordinates for N data points. Returns an empty array if no locations are found.

get_bounds()[source]

Calculates the 3D Axis-aligned bounding box of the operation from its process data.

This method checks if the operation has been processed before attempting to calculate the bounds. A warning is logged if it has not been processed.

Returns:

((min_x, min_y, min_z), (max_x, max_y, max_z)). Returns None if the operation has not been processed or contains no location data.

Return type:

A tuple containing the minimum and maximum coordinates

get_statistics()[source]

Compiles key statistics about the operation into a dictionary.

get_total_elapsed_time() float[source]

Calculates the total elapsed time for the operation.

Returns:

The total elapsed time in seconds as a float.

process_data_to_numpy_dict(bounds: Tuple[int, int] = None) Dict[str, numpy.ndarray][source]

Converts process_data to a dict of NumPy arrays, keyed by attribute name.

Parameters:

bounds – Optional (start, end) index bounds. Defaults to the full list.

Returns:

A dict mapping each ProcessData attribute name to a NumPy array. Returns an empty dict if the bounds is zero-length.

Raises:
  • TypeError – If bounds is not a tuple/list, or if process_data contains mixed types.

  • ValueError – If bounds does not have exactly 2 elements.

  • IndexError – If bounds are out of range.

property arrays: ProcessDataArrays

Columnar view of process_data; built once on first access.

commands: List[gcode_reader.emulate.commands.Command] = []
motion_profile: List = []
name: str = None
process_data: List[ProcessData] = []
processed_by_machine: type = None
class gcode_reader.emulate.operations.ProcessData[source]

Stores data associated with Command execution by a Machine.

attribute_names()[source]

Convenience function for getting attribute_names

to_dict()[source]
distance: float = 0.0
elapsed_time: float = 0.0
feed_rate: float = 0.0
location: Tuple[float, float, float] = None
relative_movement: Tuple[float, float, float] = None
tool_direction: Tuple[float, float, float] = (0, 0, 1)
class gcode_reader.emulate.operations.ProcessDataArrays[source]

Columnar (struct-of-arrays) view of a List[ProcessData].

Downstream consumers (motion.py, additive_part.py) iterate the object list to extract numpy arrays, paying O(N) Python overhead twice. Building this once after the machine loop lets both consumers read pre-built arrays directly.

Construction is intentionally lazy via from_process_data_list() rather than being built inside the machine loop so that the ProcessData objects (still needed for tool callbacks) remain the primary output.

classmethod from_process_data_list(process_data: list) ProcessDataArrays[source]

Build columnar arrays from a List[ProcessData] in a single pass.

class gcode_reader.emulate.operations.SubtractiveOperation[source]

Bases: Operation

An Operation specialized for subtractive processes (e.g., milling, CNC).

class gcode_reader.emulate.operations.SubtractiveProcessData[source]

Bases: ProcessData

Stores process_data associated with Command execution by a Machine for a subtractive operation.

removed_volume: float = 0.0
spindle_speed: float = 0.0
gcode_reader.emulate.operations.make_process_data(operation_cls: type) ProcessData[source]

Return a fresh ProcessData instance appropriate for operation_cls.

If operation_cls is not a class registered in the map (e.g. a caller accidentally passed an instance), falls back to a plain ProcessData.

gcode_reader.emulate.operations.register_process_data(operation_cls: type, process_data_cls: type) None[source]

Associate an Operation subclass with the ProcessData subclass it produces.

Parameters:
  • operation_cls – The Operation subclass (e.g. AdditiveOperation).

  • process_data_cls – The ProcessData subclass to instantiate for it.