Skip to content
Edit this page

ictdesigntools.draw.shapes

What a drawing is made of: shapes, groups, and components placed with Use.

Coordinates are drawing units (millimetres unless the drawing says otherwise), x to the right and y down from the top-left, as in SVG. Each shape's look comes from its named style in the drawing, overridden by any of fill, stroke, width and dash set on the shape.

Meta dataclass

Meta(
    id: str = "",
    kind: str = "",
    data: tuple[tuple[str, str], ...] = (),
)

What a part is, for interactive pages and cross-references: an id unique in the drawing, a kind ("port", "conduit", …) and string data. The SVG output writes them as data-id, data-kind and data-<key> attributes.

Hatch dataclass

Hatch(
    pattern: str = "SOLID",
    scale: float = 1.0,
    color: int | None = None,
    angle: float = 0.0,
    outline: bool = False,
)

How a closed shape is filled in CAD: "SOLID" or a named pattern such as "AR-CONC", "ANSI31" or "EARTH", with its scale and an AutoCAD colour index (None: the layer's colour).

Style dataclass

Style(
    fill: str | None = None,
    stroke: str | None = None,
    width: float | None = None,
    dash: bool | None = None,
    color: str | None = None,
    hatch: Hatch | None = None,
    cad_color: bool | None = None,
)

A named look. None leaves a value to the next style down (the drawing's, then the built-in default); colours are CSS hex strings.

over

over(base: Style) -> Style

This style with base filling what it leaves unset.

Source code in src/ictdesigntools/draw/shapes.py
def over(self, base: Style) -> Style:
    """This style with ``base`` filling what it leaves unset."""
    pairs = zip(_fields(self), _fields(base), strict=True)
    return Style(*(mine if mine is not None else theirs for mine, theirs in pairs))

Ring dataclass

Ring(
    cx: float,
    cy: float,
    r_outer: float,
    r_inner: float,
    color: str,
    bore: str = "#fcfcfb",
    layer: str = "0",
    title: str = "",
    edge: str | None = None,
    cad_color: bool = False,
    meta: Meta = Meta(),
    style: str = "",
)

A tube wall between two radii, with its bore filled: a conduit, duct or tube in section. edge outlines both radii so a light wall still shows; cad_color carries the wall colour into CAD.

Polygon dataclass

Polygon(
    points: tuple[tuple[float, float], ...],
    fill: str | None = None,
    stroke: str | None = None,
    width: float | None = None,
    dash: bool | None = None,
    layer: str = "0",
    title: str = "",
    style: str = "",
    meta: Meta = Meta(),
)

A closed outline through points.

Polyline dataclass

Polyline(
    points: tuple[tuple[float, float], ...],
    stroke: str | None = None,
    width: float | None = None,
    dash: bool | None = None,
    layer: str = "0",
    title: str = "",
    style: str = "",
    meta: Meta = Meta(),
)

An open path through points, e.g. a cable's route or a leader.

Arc dataclass

Arc(
    cx: float,
    cy: float,
    r: float,
    start: float,
    end: float,
    stroke: str | None = None,
    width: float | None = None,
    dash: bool | None = None,
    layer: str = "0",
    style: str = "",
    meta: Meta = Meta(),
)

Part of a circle from start to end degrees, counter-clockwise as seen on the page, with 0 pointing right.

Dim dataclass

Dim(
    x1: float,
    y1: float,
    x2: float,
    y2: float,
    text: str,
    offset: float,
    vertical: bool = False,
    layer: str = "DIM",
)

A linear dimension between two points, drawn offset to one side. Its text size is the drawing's font.

Earth dataclass

Earth(
    x: float,
    y: float,
    w: float,
    h: float,
    holes: tuple[
        tuple[float, float, float, float], ...
    ] = (),
    tile: float = 25.0,
    layer: str = "EARTH",
)

Soil in the CAD "EARTH" style over a rectangle, leaving out the holes (rectangles): alternating tiles of three horizontal and three vertical strokes. In DXF it is a native EARTH hatch, so CAD users can edit it.

Group dataclass

Group(
    items: tuple = (),
    transform: Transform = IDENTITY,
    title: str = "",
    layer: str = "",
    meta: Meta = Meta(),
)

Shapes moved, turned or scaled together. layer, when set, is given to children left on layer "0".

Component dataclass

Component(name: str, items: tuple = (), title: str = '')

A part drawn once, in its own coordinates, and placed many times with Use: a 1U panel, a connector, a duct bundle. SVG writes it once in <defs>; DXF makes it a block. name must be unique in the drawing.

Use dataclass

Use(
    component: Component,
    transform: Transform = IDENTITY,
    title: str = "",
    layer: str = "",
    meta: Meta = Meta(),
)

A component placed by transform.

own_style

own_style(it) -> Style

The look set on the shape itself.

Source code in src/ictdesigntools/draw/shapes.py
def own_style(it) -> Style:
    """The look set on the shape itself."""
    if isinstance(it, Line):
        return Style(stroke=it.color, width=it.width, dash=it.dash)
    if isinstance(it, Text):
        return Style(color=it.color)
    return Style(fill=getattr(it, "fill", None), stroke=getattr(it, "stroke", None),
                 width=getattr(it, "width", None), dash=getattr(it, "dash", None))  # fmt: skip