gcode_reader.emulate.exporters ============================== .. py:module:: gcode_reader.emulate.exporters Classes ------- .. autoapisummary:: gcode_reader.emulate.exporters.GcodeExporter gcode_reader.emulate.exporters.VTKExporter Module Contents --------------- .. py:class:: GcodeExporter(syntax_name='default') Translates abstract Command objects into G-code strings or data series. This class uses configurable "syntax flavors" to handle different G-code dialects. It can export a sequence of Command objects into a final G-code file or into a format suitable for data analysis (e.g., a Pandas DataFrame). .. attribute:: syntax The syntax definition dictionary for the chosen flavor. :type: dict .. attribute:: word_map A map to translate Command attribute names to G-code words. :type: dict .. attribute:: code_map A map for specific G-code numbers (e.g., rapid move code). :type: dict .. attribute:: gcode_line_helpers A list of helper methods used to construct a G-code line. :type: list .. attribute:: write_order A list of G-code word keys defining their output order. :type: list Initializes the GcodeExporter with a specific syntax flavor. :param syntax_name: The name of the syntax flavor to use, which corresponds to a definition in `gcode_reader.syntax.flavors`. Defaults to "default". :type syntax_name: str, optional .. py:method:: command_to_dict(command: gcode_reader.emulate.commands.Command) -> dict Converts a `Command` instance into a plain dict suitable for a `DataFrame` row. Prefer this over `command_to_pd_series` when building a DataFrame from many commands — passing a list of dicts to `pd.DataFrame()` is significantly faster than passing a list of `pd.Series`. :param command: The Command object to convert. :type command: `Command` :returns: A dictionary containing the command's G-code words and metadata. :rtype: dict .. py:method:: command_to_gcode_line(command: gcode_reader.emulate.commands.Command) -> str Constructs a complete G-code line string from a Command object. This method orchestrates the G-code generation process. It first converts the command to a dictionary of words, then uses the list of `gcode_line_helpers` to assemble those words into a final, space- delimited G-code string. :param command: The Command to convert into a G-code line. :type command: Command :returns: A single, formatted G-code line. :rtype: str .. py:method:: command_to_gcode_words(command: gcode_reader.emulate.commands.Command) -> dict Converts a Command's data into a dictionary of G-code words. This method uses the exporter's `word_map` to translate the Command's internal attributes (e.g., `position`) into the corresponding G-code words and values (e.g., {'X': 10, 'Y': 20}). It's the first step in converting a command to either a string or a data series. :param command: The Command object to process. :type command: Command :returns: A dictionary mapping G-code words (e.g., 'G', 'X', 'F') to their respective values. :rtype: dict .. py:method:: command_to_pd_series(command: gcode_reader.emulate.commands.Command) Converts a `Command` instance into a `pd.Series`. For bulk DataFrame construction use `command_to_dict` instead. .. py:property:: code_map .. py:attribute:: gcode_line_helpers .. py:property:: syntax .. py:property:: word_map .. py:attribute:: write_order :value: ('G', 'M', 'X', 'Y', 'Z', 'A', 'B', 'C', 'F', 'E') .. py:class:: VTKExporter Exports geometry and scalar data to PyVista and VTK formats. .. py:method:: additive_part_to_polydata(additive_part: gcode_reader.emulate.additive_part.AdditivePart, deposition_range: tuple = None, custom_scalars: dict = None) -> pyvista.PolyData :staticmethod: Converts an AdditivePart to a PyVista PolyData mesh with scalar fields. :param additive_part: The part to convert. :type additive_part: AdditivePart :param deposition_range: ``(start, end)`` pair of 0-based indices into the ordered sequence of depositing segments, selecting a contiguous subset to mesh. ``None`` includes all depositing segments. :type deposition_range: tuple, optional :param custom_scalars: Mapping of ``{name: array}`` for additional or replacement scalar arrays stored as cell data. Use this to supply measured data (e.g. temperature) or any other derived field. Array length must equal ``mesh.n_cells`` (one value per line-segment). :type custom_scalars: dict, optional :returns: Mesh with scalar arrays in ``cell_data``. :rtype: pv.PolyData :raises TypeError: If ``additive_part`` is not an ``AdditivePart``. :raises ImportError: If pyvista is not installed. .. py:method:: additive_part_to_vtk(additive_part: gcode_reader.emulate.additive_part.AdditivePart, filepath: str, binary: bool = True, deposition_range: tuple = None) :staticmethod: Exports an AdditivePart to a ``.vtk`` file with embedded scalar fields. :param additive_part: The part to export. :type additive_part: AdditivePart :param filepath: Destination path; must end with ``.vtk``. :type filepath: str :param binary: Write binary VTK format. Defaults to True. :type binary: bool, optional :param deposition_range: ``(start, end)`` pair of 0-based indices into the ordered sequence of depositing segments to export. ``None`` exports all depositing segments. :type deposition_range: tuple, optional :raises TypeError: If ``additive_part`` is not an ``AdditivePart``. :raises ValueError: If ``filepath`` does not end with ``.vtk``. :raises FileNotFoundError: If the parent directory of ``filepath`` does not exist.