ROOM » Core » C++ Classes » Shape

Shape Class

Tagged union of layout and schematic geometry (rect, polygon, path, text, arc) with optional metadata. More…

Header:#include "shape.h"
CMake:find_package(ROOM REQUIRED)
target_link_libraries(mytarget PRIVATE ROOM::room)

List of all members

Public Types

enum class TypeDiscriminator: Rect, Polygon, Path, Text, Arc.
struct RectDataAxis-aligned box and layerId (GDS BOX).
struct PolygonDataPoint hull and layerId (GDS BOUNDARY).
struct PathDataCenterline, width, and layerId (GDS PATH).
struct TextDataLabel string, position, height, and layerId (GDS TEXT).
struct ArcDataCircular arc (center, radius, angles, width) — used by Xschem wires/pins.

Public Functions

explicit Shape(RectData data)Constructs a rectangle shape.
explicit Shape(PolygonData data)Constructs a polygon shape.
explicit Shape(PathData data)Constructs a path shape.
explicit Shape(TextData data)Constructs a text shape.
explicit Shape(ArcData data)Constructs an arc shape.
Type type() constReturns the active geometry kind.
const RectData * rect() constRectangle payload when type() == Rect.
const PolygonData * polygon() constPolygon payload when type() == Polygon.
const PathData * path() constPath payload when type() == Path.
const TextData * text() constText payload when type() == Text.
const ArcData * arc() constArc payload when type() == Arc.
std::vector<Property> & properties()Shape metadata for modification.
const std::vector<Property> & properties() constShape metadata for read-only access.

Detailed Description

A room::Shape stores one piece of layout geometry inside a Block. The active variant is selected by type(); use the matching accessor (rect(), polygon(), …) to read payload data. Each variant carries a layerId index into the view or library LayerSpec table—not a raw GDS layer number.

Shapes may carry Property lists (for example GDS user attributes encoded as gds.prop.<attr> after import).

Member Type Documentation

enum class Type { Rect, Polygon, Path, Text, Arc }

ValueSourceAccessor
RectGDS BOXrect()
PolygonGDS BOUNDARYpolygon()
PathGDS PATHpath()
TextGDS TEXTtext()
ArcXschem / schematicarc()

struct RectData { Box box; std::uint32_t layerId; }

Rectangle geometry in DBU. box uses lower-left / upper-right corners (Box).

struct PolygonData { std::vector<Point> points; std::uint32_t layerId; }

Closed polygon hull in DBU vertex order.

struct PathData { std::vector<Point> points; std::uint32_t width; std::uint32_t layerId; }

Centerline polyline; width is full path width in DBU (0 allowed).

struct TextData { Point position; std::string text; std::uint32_t layerId; std::uint32_t height; }

Text anchor, string payload, layer index, and character height in DBU.

struct ArcData { Point center; double radius; double startAngle; double endAngle; std::uint32_t width; std::uint32_t layerId; }

Circular arc in DBU. Angles in degrees; width is stroke width for schematic wires.

Member Function Documentation

explicit Shape(RectData data)

Constructs a rectangle shape.

ParameterDescription
dataBounding box and layer index.

explicit Shape(PolygonData data)

Constructs a polygon shape.

explicit Shape(PathData data)

Constructs a path shape.

explicit Shape(TextData data)

Constructs a text label shape.

Type type() const

Returns which geometry variant is stored.

Returns: One of Type::Rect, Polygon, Path, Text, or Arc.

const RectData * rect() const

Accesses rectangle data when the shape type is Rect.

Returns: Non-null pointer if types match; otherwise nullptr.

const PolygonData * polygon() const

Accesses polygon data when the shape type is Polygon.

Returns: Non-null pointer if types match; otherwise nullptr.

const PathData * path() const

Accesses path data when the shape type is Path.

Returns: Non-null pointer if types match; otherwise nullptr.

const TextData * text() const

Accesses text data when the shape type is Text.

Returns: Non-null pointer if types match; otherwise nullptr.

std::vector<Property> & properties()

Returns shape metadata for modification.

const std::vector<Property> & properties() const

Returns shape metadata for read-only access.

Private Variables

Private members are implementation details. Do not access them from user code.

Type m_typeActive geometry discriminator.
RectData m_rectStorage when type is Rect.
PolygonData m_polygonStorage when type is Polygon.
PathData m_pathStorage when type is Path.
TextData m_textStorage when type is Text.
ArcData m_arcStorage when type is Arc.
std::vector<Property> m_propertiesAttached metadata.

Example

room::Block & block = layout.block();

block.shapes().emplace_back(room::Shape::PolygonData{
    {{{0,0}, {1000,0}, {1000,500}, {0,500}}}, 0});

block.shapes().emplace_back(room::Shape::PathData{
    {{{500,500}, {5000,5000}}}, 200, 1});

for (const room::Shape & shape : block.shapes()) {
    if (shape.type() == room::Shape::Type::Polygon) {
        const auto *poly = shape.polygon();
        // poly->points, poly->layerId
    }
}