Skip to main content

Layer2D

Layer2D is a layer for a 2D plotter. Layers are added via the Plotter2D.add_layer method.

Layer2D extends from the abstract class Layer.

init

__init__(
self, plotter_x_min: float, plotter_y_min: float, plotter_x_max: float, plotter_y_max: float, feed_rate: float, handle_out_of_bounds: Union[Literal['Warning'], Literal['Error']], color: Optional[str], line_width: float, include_comments: bool, preview_only: bool = False )
-> None

Args:

  • plotter_x_min (float) : The minimum X-coordinate of the plotter.
  • plotter_y_min (float) : The minimum Y-coordinate of the plotter.
  • plotter_x_max (float) : The maximum X-coordinate of the plotter.
  • plotter_y_max (float) : The maximum Y-coordinate of the plotter.
  • feed_rate (float) : The feed rate for the plotter.
  • handle_out_of_bounds (Warning | Error, optional): How to handle out-of-bounds points. Warning will print a warning, skip the point, and continue. Error will throw an error and stop. Defaults to Warning.
  • color (str, optional) : The color of the layer. Defaults to a random color.
  • line_width (float) : The width of the line being plotted.
  • preview_only (bool, optional) : If true, the layer will not be plotted. Defaults to False.
  • include_comments (bool, optional) : Whether to include comments in the G-Code files. Useful for learning about G-Code and debugging.

add_circle

add_circle(
self, x_center: float, y_center: float, radius: float, num_points: int = 36, raise_plotter_head_after_path: bool = True, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Adds a circle to the layer. add_circle calls add_path under the hood, for more control, use add_path directly.

Args:

  • x_center (float) : The x-coordinate of the center of the circle.
  • y_center (float) : The y-coordinate of the center of the circle.
  • radius (float) : The radius of the circle.
  • num_points (int) : The number of points to use to approximate the circle. More points leads to a circle with less visible straight lines. Defaults to 36.
  • raise_plotter_head_after_path (bool, optional) : Whether to raise the plotter head after the path is complete. Useful to set to False if subsequent paths are plotted nearby. Defaults to True.
  • instruction_phase (setup | plotting | teardown, optional): The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

add_comment

add_comment(
self, text: str, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] )
-> Self

Add a comment to the layer.

Args:

  • text (str): The text to add.
  • instruction_phase (setup | plotting | teardown, optional): The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer: The Layer object. Allows for chaining of add methods.

add_line

add_line(
self, x_start: float, y_start: float, x_end: float, y_end: float, raise_plotter_head_after_path: bool = True, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Add a line to the layer. add_line calls add_path under the hood, for more control, use add_path directly.

Args:

  • x_start (float) : The x-coordinate of the starting point of the line.
  • y_start (float) : The y-coordinate of the starting point of the line.
  • x_end (float) : The x-coordinate of the ending point of the line.
  • y_end (float) : The y-coordinate of the ending point of the line.
  • raise_plotter_head_after_path (bool, optional) : Whether to raise the plotter head after the path is complete. Useful to set to False if subsequent paths are plotted nearby. Defaults to True.
  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

add_path

add_path(
self, points: List[Tuple[float, float]], raise_plotter_head_after_path: bool = True, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Add a path to the layer. A path is a series of points that are connected by lines.

Args:

  • points (List[Tuple[float, float]]) : An array of (x,y) points to add.
  • raise_plotter_head_after_path (bool, optional) : Whether to raise the plotter head after the path is complete. Useful to set to False if subsequent paths are plotted nearby. Defaults to True.
  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

add_point

add_point(
self, x: float, y: float, raise_plotter_head_after_path: bool = True, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Add a point to the layer. add_point calls add_path under the hood, for more control, use add_path directly.

Args:

  • x (float) : The x-coordinate of the point.
  • y (float) : The y-coordinate of the point.
  • raise_plotter_head_after_path (bool, optional) : Whether to raise the plotter head after the path is complete. Useful to set to False if subsequent paths are plotted nearby. Defaults to True.
  • instruction_phase (setup | plotting | teardown, optional): The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

add_rectangle

add_rectangle(
self, x_start: float, y_start: float, x_end: float, y_end: float, raise_plotter_head_after_path: bool = True, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Adds a rectangle to the layer. add_rectangle calls add_path under the hood, for more control, use add_path directly.

Args:

  • x_start (float) : The x-coordinate of the starting point of the rectangle.
  • y_start (float) : The y-coordinate of the starting point of the rectangle.
  • x_end (float) : The x-coordinate of the ending point of the rectangle.
  • y_end (float) : The y-coordinate of the ending point of the rectangle.
  • raise_plotter_head_after_path (bool, optional) : Whether to raise the plotter head after the path is complete. Useful to set to False if subsequent paths are plotted nearby. Defaults to True.
  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

add_text

add_text(
self, text: str, font_size: float, x_start: float, y_start: float, char_spacing: Optional[float] = None, point_offset: Optional[float] = None, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Adds a text to the layer. add_text calls add_path under the hood, for more control, use add_path directly.

Args:

  • text (str) : The text to add.
  • font_size (float) : The height of each character of text in mm.
  • x_start (float) : The x-coordinate of the starting point of the text. Located to the left of the text.
  • y_start (float) : The y-coordinate of the starting point of the text. Located at the bottom of the text.
  • char_spacing (float) : The spacing between each character in mm. Defaults to layer line_width.
  • point_offset (float, optional) : The offset of the point in the character, units are mm. Used for characters such as !. Defaults to the layer line_width.
  • instruction_phase (setup | plotting | teardown, optional): The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

get_min_and_max_points

get_min_and_max_points(
self )
-> Dict[str, float]

Find the min and max plot points of the layer.

Returns:

  • dict : {x_min (float), y_min (float), x_max (float), y_max (float)} A dictionary containing the min and max plot points of the layer.

get_plotting_data

get_plotting_data(
self )
-> Dict[str, List[str]]

Get current plotting data.

Returns:

  • dict: {"setup": [], "plotting": [], "teardown": []} A dictionary containing instruction phases - setup, plotting, and teardown as an array of G-Code instruction strings per layer. Mostly used for testing purposes.

preview_paths

preview_paths(
self )
-> List[List[Tuple[float, float]]]

Generate an array of paths for the given layer. This will be used by the Plotter to generate a preview image of what will be plotted. Only looks at instructions during the plotting phase.

Returns:

  • List[List[Tuple[float, float]]] An array of paths for the given layer.

save

save(
self, file_path: str )
-> None

Saves the layer instructions to a file at the specified file path.

Args:

  • file_path (str) : The path to the file where the layer instructions will be saved.

set_feed_rate

set_feed_rate(
self, feed_rate: float, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Set the speed at which the plotter head moves.

Args:

  • feed_rate (float) : The feed rate to set.
  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

set_mode_to_navigation

set_mode_to_navigation(
self, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Separate plotting instrument from plotting surface. Should be used once plotting a path is complete before moving on to the next path.

Args:

  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.

set_mode_to_plotting

set_mode_to_plotting(
self, instruction_phase: Union[Literal['setup'], Literal['plotting'], Literal['teardown']] = 'plotting' )
-> Self

Connect plotting instrument to plotting surface. Should be used when starting a path.

Args:

  • instruction_phase (setup | plotting | teardown, optional) : The instruction phase of plotting to send the instruction to. Defaults to plotting.

Returns:

  • Layer : The Layer object. Allows for chaining of add methods.