Entity#

class zeroheliumkit.src.core.Entity[source]#

Bases: object

Represents collections of shapely objects organized by layers and linked together. This class provides methods to add, remove, rename, and manipulate layers containing geometric objects (such as polygons and multipolygons), as well as to handle Anchors and Skeletone. It supports various geometric operations including union, difference, intersection, simplification, cropping, and modification of polygon points.

Parameters:
  • layers – List of layer names.

  • colors – ColorHandler class, which handles info about colors of layers and their order.

  • errors – Contains error messages.

  • skeletone (Skeletone) – Represents a collection of lines linked to the Entity, which is an instance of the Skeletone class.

  • anchors (MultiAnchor) – Represents the anchor points of the Entity, which are instances of MultiAnchor.

Methods

add(layer)

Adds a layer to the class with the given name and geometry.

clean()

Removes all layers with empty polygons

copy([rename_anchors, with_suffix])

Creates a deep copy of the Entity instance.

crop(geom[, loc])

Crops polygons in all layers.

cut(geom[, loc])

Cuts the specified polygon from polygons in all layers.

export_dict([remove_holes])

Returns all layer names and their corresponding geometries in a Dictionary.

export_dxf(filename, layer_cfg)

Exports layers as a DXF file.

export_gds(filename, layer_cfg)

Exports all layers as a GDS file.

export_pickle(filename)

Exports all layers as a pickle file.

get(lname)

Retrieves a layer by its name.

has_layer(name)

Check if a layer exists in the class.

mirror(aroundaxis[, keep_original, ...])

Mirror all objects around a specified axis.

move(dx, dy)

Moves all objects in the class by the specified (dx, dy) offset.

quickplot([size, color_config, zoom, ...])

Plots the Entity object with predefined colors for each layer.

remove(lname)

Removes a layer from the class.

rename(old, new)

Changes the name of a layer/attribute in the class.

rotate([angle, origin])

Rotates all objects in the class

scale([xfact, yfact, origin])

Scales all objects by the specified factors along the x and y axes.

slice(slice_line)

Slices polygons in a layer using a given line.

snap_to(point_from, point_to)

Snaps all objects in the class so that point_from aligns with point_to.

Attributes

anchors

colors

errors

layers

skeletone

get(lname: str) Layer | None[source]#

Retrieves a layer by its name.

Parameters:

lname (str) – The name of the layer.

Returns:

The layer with the specified name, or None if not found.

Return type:

Layer

add(layer: Layer)[source]#

Adds a layer to the class with the given name and geometry.

Parameters:

layer (Layer) – The layer to be added.

Returns:

Updated instance (self) of the class with the new layer added.

remove(lname: str)[source]#

Removes a layer from the class.

Parameters:

lname (str) – The name of the layer.

Returns:

Updated instance (self) of the class with the layer removed.

rename(old: str, new: str) None[source]#

Changes the name of a layer/attribute in the class.

Parameters:
  • old (str) – The old name.

  • new (str) – The new name.

Returns:

Updated instance (self) of the class with the layer renamed.

has_layer(name: str) bool[source]#

Check if a layer exists in the class.

Parameters:

name (str) – The name of the layer.

Returns:

True if the layer exists, False otherwise.

Return type:

bool

cut(geom: Polygon | MultiPolygon, loc: tuple[float, float] = None)[source]#

Cuts the specified polygon from polygons in all layers.

Parameters:

polygon (Polygon | MultiPolygon) – The polygon used for cutting

Returns:

Updated instance (self) of the class with the specified polygon cut from all layers.

crop(geom: Polygon | MultiPolygon, loc: tuple[float, float] = None)[source]#

Crops polygons in all layers.

Parameters:

geom (Polygon | MultiPolygon) – The cropping polygon.

Returns:

Updated instance (self) of the class with polygons in all layers cropped by the specified polygon.

slice(slice_line: LineString | list[LineString])[source]#

Slices polygons in a layer using a given line.

Parameters:
  • lname (str | list[str]) – The name of the layer.

  • slice_line (LineString) – The line used for slicing.

copy(rename_anchors: bool = False, with_suffix: str = '_copy') Entity[source]#

Creates a deep copy of the Entity instance. Optionally updates the labels of the anchors with a specified suffix.

Parameters:
  • rename_anchors (bool, optional) – Whether to rename anchor labels in the copied instance. Defaults to False.

  • with_suffix (str, optional) – Suffix to append to anchor labels in the copied instance.

Returns:

A new instance of Entity with the same layers, skeletone, and anchors

Return type:

Entity

clean()[source]#

Removes all layers with empty polygons

rotate(angle: float = 0, origin=(0, 0))[source]#

Rotates all objects in the class

Parameters:
  • angle (float, optional) – rotation angle. Defaults to 0.

  • origin (str, optional) – rotations are made around this point. Defaults to (0,0).

Returns:

Updated instance (self) of the class with all objects rotated.

move(dx: float, dy: float)[source]#

Moves all objects in the class by the specified (dx, dy) offset.

Parameters:
  • dx (float) – The x-offset to move by.

  • dy (float) – The y-offset to move by.

Returns:

Updated instance (self) of the class with all objects moved.

snap_to(point_from: tuple | Point | Anchor, point_to: tuple | Point | Anchor)[source]#

Snaps all objects in the class so that point_from aligns with point_to.

Parameters:
  • point_from (tuple | Point | Anchor) – The point to be moved.

  • point_to (tuple | Point | Anchor) – The target point to snap to.

Returns:

Updated instance (self) of the class with all objects snapped.

scale(xfact: float = 1.0, yfact: float = 1.0, origin: tuple = (0, 0))[source]#

Scales all objects by the specified factors along the x and y axes.

Parameters:
  • xfact (float, optional) – scale along x-axis. Defaults to 1.0.

  • yfact (float, optional) – scale along y-axis. Defaults to 1.0.

  • origin ((x,y), optional) – scale with respect to an origin (x,y). Defaults to (0,0).

Returns:

Updated instance (self) of the class with all objects scaled.

mirror(aroundaxis: str, keep_original: bool = True, update_labels: bool = True)[source]#

Mirror all objects around a specified axis.

Parameters:
  • aroundaxis (str) – Defines the mirror axis. Only ‘x’ or ‘y’ are supported.

  • update_labels (bool, optional) – Whether to update the labels after mirroring. Defaults to False.

  • keep_original (bool, optional) – Whether to keep the original objects after mirroring. Defaults to False.

Raises:

TypeError – If the ‘aroundaxis’ is not ‘x’ or ‘y’.

Returns:

Updated instance (self) of the class with all objects mirrored.

export_dict(remove_holes: bool = False) dict[source]#

Returns all layer names and their corresponding geometries in a Dictionary. Includes anchors and skeletone.

Parameters:

remove_holes (bool, optional) – Flag to remove holes from polygons. Defaults to False.

Returns:

A dictionary containing layer names as keys and their corresponding geometries as values.

Return type:

zhk_dict(dict)

export_pickle(filename: str) None[source]#

Exports all layers as a pickle file.

Parameters:

filename (str) – The name of the pickle file to be exported.

export_gds(filename: str, layer_cfg: dict) None[source]#

Exports all layers as a GDS file.

Parameters:
  • filename (str) – The name of the gds file to be exported.

  • layer_cfg (dict) – A dictionary containing the layer configuration. See gdspy docs for ‘datatype’ details.

export_dxf(filename: str, layer_cfg: list) None[source]#

Exports layers as a DXF file.

Parameters:
  • filename (str) – The name of the dxf file to be exported.

  • layer_cfg (dict) – A list of layer to be exported.

quickplot(size='large', color_config: dict = None, zoom: tuple = None, show_idx: bool = False, off: list = [], labels: bool = False, draw_anchor_dir: bool = True, ax=None, **kwargs) None[source]#

Plots the Entity object with predefined colors for each layer.

Parameters:
  • plot_config (dict) – dict of ordered layers (keys) with tuples of the color and alpha of the layer (values)

  • zoom (tuple, optional) – ((x0, y0), zoom_scale, aspect_ratio). Defaults to None.

Returns:

The axis with the plotted Entity object.

Return type:

ax (matplotlib.axes.Axes)