gcode_reader.emulate.operations =============================== .. py:module:: gcode_reader.emulate.operations Classes ------- .. autoapisummary:: gcode_reader.emulate.operations.AdditiveOperation gcode_reader.emulate.operations.AdditiveProcessData gcode_reader.emulate.operations.Operation gcode_reader.emulate.operations.ProcessData gcode_reader.emulate.operations.ProcessDataArrays gcode_reader.emulate.operations.SubtractiveOperation gcode_reader.emulate.operations.SubtractiveProcessData Functions --------- .. autoapisummary:: gcode_reader.emulate.operations.make_process_data gcode_reader.emulate.operations.register_process_data Module Contents --------------- .. py:class:: AdditiveOperation Bases: :py:obj:`Operation` An `Operation` specialized for additive processes (e.g., 3D printing). .. py:class:: AdditiveProcessData Bases: :py:obj:`ProcessData` Stores ProcessData associated with Command execution by a Machine for an additive operation. .. py:attribute:: bead_area :type: float :value: None .. py:attribute:: deposited_volume :type: float :value: 0.0 .. py:attribute:: extruder_type :type: type :value: None .. py:class:: Operation Represents a single manufacturing step. Holds sequence of commands and stores the resulting process data after simulation or execution by a machine model. .. attribute:: name A human-readable name for the operation. .. attribute:: commands A list of `Command` objects that define the machine's actions. .. attribute:: process_data A list of `ProcessData` objects, populated after processing, containing detailed information like tool locations and timing. .. attribute:: processed_by_machine Stores the type of the machine that last processed this operation. .. py:method:: get_all_locations() -> numpy.ndarray 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. .. py:method:: get_bounds() 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. :rtype: A tuple containing the minimum and maximum coordinates .. py:method:: get_statistics() Compiles key statistics about the operation into a dictionary. .. py:method:: get_total_elapsed_time() -> float Calculates the total elapsed time for the operation. :returns: The total elapsed time in seconds as a float. .. py:method:: process_data_to_numpy_dict(bounds: Tuple[int, int] = None) -> Dict[str, numpy.ndarray] Converts process_data to a dict of NumPy arrays, keyed by attribute name. :param 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. :raises ValueError: If bounds does not have exactly 2 elements. :raises IndexError: If bounds are out of range. .. py:property:: arrays :type: ProcessDataArrays Columnar view of process_data; built once on first access. .. py:attribute:: commands :type: List[gcode_reader.emulate.commands.Command] :value: [] .. py:attribute:: motion_profile :type: List :value: [] .. py:attribute:: name :type: str :value: None .. py:attribute:: process_data :type: List[ProcessData] :value: [] .. py:attribute:: processed_by_machine :type: type :value: None .. py:class:: ProcessData Stores data associated with Command execution by a Machine. .. py:method:: attribute_names() Convenience function for getting attribute_names .. py:method:: to_dict() .. py:attribute:: distance :type: float :value: 0.0 .. py:attribute:: elapsed_time :type: float :value: 0.0 .. py:attribute:: feed_rate :type: float :value: 0.0 .. py:attribute:: location :type: Tuple[float, float, float] :value: None .. py:attribute:: relative_movement :type: Tuple[float, float, float] :value: None .. py:attribute:: tool_direction :type: Tuple[float, float, float] :value: (0, 0, 1) .. py:class:: ProcessDataArrays 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. .. py:method:: from_process_data_list(process_data: list) -> ProcessDataArrays :classmethod: Build columnar arrays from a List[ProcessData] in a single pass. .. py:class:: SubtractiveOperation Bases: :py:obj:`Operation` An `Operation` specialized for subtractive processes (e.g., milling, CNC). .. py:class:: SubtractiveProcessData Bases: :py:obj:`ProcessData` Stores process_data associated with Command execution by a Machine for a subtractive operation. .. py:attribute:: removed_volume :type: float :value: 0.0 .. py:attribute:: spindle_speed :type: float :value: 0.0 .. py:function:: make_process_data(operation_cls: type) -> ProcessData 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``. .. py:function:: register_process_data(operation_cls: type, process_data_cls: type) -> None Associate an Operation subclass with the ProcessData subclass it produces. :param operation_cls: The Operation subclass (e.g. AdditiveOperation). :param process_data_cls: The ProcessData subclass to instantiate for it.