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) |
Public Types
| enum class Type | Discriminator: Rect, Polygon, Path, Text, Arc. |
| struct RectData | Axis-aligned box and layerId (GDS BOX). |
| struct PolygonData | Point hull and layerId (GDS BOUNDARY). |
| struct PathData | Centerline, width, and layerId (GDS PATH). |
| struct TextData | Label string, position, height, and layerId (GDS TEXT). |
| struct ArcData | Circular 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() const | Returns the active geometry kind. |
| const RectData * rect() const | Rectangle payload when type() == Rect. |
| const PolygonData * polygon() const | Polygon payload when type() == Polygon. |
| const PathData * path() const | Path payload when type() == Path. |
| const TextData * text() const | Text payload when type() == Text. |
| const ArcData * arc() const | Arc payload when type() == Arc. |
| std::vector<Property> & properties() | Shape metadata for modification. |
| const std::vector<Property> & properties() const | Shape 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 }
| Value | Source | Accessor |
|---|---|---|
Rect | GDS BOX | rect() |
Polygon | GDS BOUNDARY | polygon() |
Path | GDS PATH | path() |
Text | GDS TEXT | text() |
Arc | Xschem / schematic | arc() |
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.
| Parameter | Description |
|---|---|
data | Bounding 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_type | Active geometry discriminator. |
RectData m_rect | Storage when type is Rect. |
PolygonData m_polygon | Storage when type is Polygon. |
PathData m_path | Storage when type is Path. |
TextData m_text | Storage when type is Text. |
ArcData m_arc | Storage when type is Arc. |
std::vector<Property> m_properties | Attached 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
}
}