# CADD Drawing Guide

## Overview

**CADD (Computer-Aided Design and Drafting)** in ParamML is used to create 2D technical drawings for cross-sections, elevations, and detail views. CADD drawings are parametric visualizations that automatically update when input parameters change.

**Key Concepts:**

* CADD drawings are defined using XML object types with `T="CADD"` as the container
* All shapes, lines, circles, and annotations are parametric
* Coordinates are defined using inline `X`, `Y` attributes
* Use `Guard` or `GuardX` for conditional rendering
* Use `T="Repeat"` for arrays of objects (e.g., reinforcement bars)

**CADD Object Types:**

1. [`T="CADD"`](#tcadd---drawing-container) - Drawing Container
2. [`T="CADDShape"`](#tcaddshape---2d-polygon) - 2D Polygon/Polyline
3. [`T="CADDCircle"`](#tcaddcircle---circle) - Circle/Reinforcement Bar
4. [`T="CADDDimensionLine"`](#tcadddimensionline---dimension-annotation) - Dimension Annotation
5. [`T="CADDLine"`](#tcaddline---open-polyline) - Open Polyline
6. [`T="CADDText"`](#tcaddtext---text-label) - Text Labels

***

## `T="CADD"` - Drawing Container

The main container for a CADD drawing. Contains all shapes, dimension lines, text, and other drawing elements.

**Attributes:**

* `N` (String): Name of the drawing

**Example:**

```xml
<O N="BeamSection" T="CADD">
  <!-- Shapes, dimensions, text, etc. -->
</O>
```

***

## `T="CADDShape"` - 2D Polygon

Draws closed polygons (filled shapes) using a series of points. Points are connected in order and automatically closed.

**Attributes:**

* `N` (String): Name of the shape
* `Color` (String, optional): Line/fill color (e.g., "black", "red", "rgb(255,0,0)")
* `Thickness` (Number, optional): Line thickness in pixels (default: 1)
* `LineStyle` (Array, optional): Dash pattern `[dashLength, gapLength]` (e.g., `[6,3]`, `[10,30]`)
* `Guard` or `GuardX` (Expression, optional): Conditional rendering
* `X`, `Y` (Number, optional): Shape offset from origin

**Children:** Multiple `T="Point"` objects defining the polygon vertices

**Example:**

```xml
<!-- Simple rectangle -->
<O N="Rectangle" T="CADDShape">
    <O T="Point" Y="0" X="0" />
    <O T="Point" Y="0" X="10" />
    <O T="Point" Y="5" X="10" />
    <O T="Point" Y="5" X="0" />
</O>

<!-- Dashed outline with conditional rendering -->
<O N="DeckOutline" T="CADDShape" LineStyle="[10,30]" GuardX="ShowDeck .EQ. 1">
    <O T="Point" Y="0" X="-Width/2" />
    <O T="Point" Y="Depth" X="-Width/2" />
    <O T="Point" Y="Depth" X="Width/2" />
    <O T="Point" Y="0" X="Width/2" />
</O>
```

**Notes:**

* Points are automatically closed (last point connects to first)
* Use `LineStyle="[dashLength,gapLength]"` for dashed/dotted lines
* Common patterns: `[6,3]` = short dash, `[10,30]` = long dash with gap

***

## `T="CADDCircle"` - Circle

Draws circles, typically used for reinforcement bars in concrete sections or other circular features.

**Attributes:**

* `N` (String, optional): Name of the circle
* `X`, `Y` (Number): Center coordinates
* `Radius` (Number or Parameter): Circle radius
* `Color` (String, optional): Fill/stroke color
* `Thickness` (Number, optional): Line thickness in pixels
* `LineStyle` (Array, optional): Dash pattern `[dashLength, gapLength]`
* `Segments` (Number, optional): Number of segments for smoothness (default: 36)
* `RZ` (Number, optional): Rotation angle in degrees (usually 0)
* `Guard` (Expression, optional): Conditional rendering

**Example:**

```xml
<!-- Simple reinforcement bar -->
<O T="CADDCircle" X="0" Y="10" Radius="0.5" Color="black" />

<!-- Parametric circle with dash pattern -->
<O N="ReinforcementBar" T="CADDCircle"
   X="BarLocationX"
   Y="BarLocationY"
   Color="black"
   Thickness="1"
   LineStyle="[6,3]"
   RZ="0">
    <P N="Radius" V="BarDiameter/2" />
</O>
```

**Notes:**

* `Radius` can be defined as an attribute or as a child `<P>` parameter
* Use `Segments="36"` for smooth circles (higher = smoother but slower)
* `RZ="0"` is standard for circles (rotation doesn't affect appearance)

***

## `T="CADDDimensionLine"` - Dimension Annotation

Draws dimension lines with arrows showing measurements. Requires exactly 3 points.

**Structure:**

* **Point 1:** Start of dimension (measured element's start)
* **Point 2:** End of dimension (measured element's end)
* **Point 3:** Identical to Point 2 + offset (determines dimension line placement)

**Dimension Direction Rules:**

* **Horizontal dimensions:** Points 1 and 2 have same Y, different X (left to right)
* **Vertical dimensions:** Points 1 and 2 have same X, different Y (bottom to top)
* **Offset:** Third point adds offset in perpendicular direction

**Attributes:**

* `N` (String): Name of the dimension
* `Guard` or `GuardX` (Expression, optional): Conditional rendering

**Children:** Exactly 3 `T="Point"` objects

**Example:**

```xml
<!-- Horizontal: Width measurement (offset +2 above) -->
<O N="WidthDimension" T="CADDDimensionLine">
    <O T="Point" X="0" Y="0" />              <!-- Start: left edge -->
    <O T="Point" X="Width" Y="0" />          <!-- End: right edge -->
    <O T="Point" X="Width" Y="2" />          <!-- Offset: +2 in Y direction -->
</O>

<!-- Vertical: Height measurement (offset +3 to right) -->
<O N="HeightDimension" T="CADDDimensionLine">
    <O T="Point" X="Width" Y="0" />          <!-- Start: bottom -->
    <O T="Point" X="Width" Y="Height" />     <!-- End: top -->
    <O T="Point" X="Width+3" Y="Height" />   <!-- Offset: +3 in X direction -->
</O>

<!-- Dimension without offset (inside element) -->
<O N="ThicknessDimension" T="CADDDimensionLine">
    <O T="Point" X="-Thickness/2" Y="Height/2" />
    <O T="Point" X="Thickness/2" Y="Height/2" />
    <O T="Point" X="Thickness/2" Y="Height/2" />  <!-- No offset -->
</O>
```

**Notes:**

* Works best for horizontal and vertical dimensions
* Third point determines where dimension line appears relative to measured element
* For no offset, make third point identical to second point

***

## `T="CADDLine"` - Open Polyline

Draws open polylines (lines that don't close back to start point).

**Attributes:**

* `N` (String): Name of the line
* `Color` (String, optional): Line color
* `Thickness` (Number, optional): Line thickness in pixels
* `LineStyle` (Array, optional): Dash pattern

**Children:** Multiple `T="Point"` objects defining the line path

**Example:**

```xml
<!-- Simple line -->
<O N="CenterLine" T="CADDLine" Color="red" LineStyle="[10,30]">
    <O T="Point" X="0" Y="0" />
    <O T="Point" X="10" Y="0" />
    <O T="Point" X="10" Y="5" />
</O>
```

**Notes:**

* Unlike `CADDShape`, the line does NOT automatically close
* Use for reference lines, construction lines, or open paths

***

## `T="CADDText"` - Text Label

Adds text annotations to drawings. Text can include parameter values using `|paramName|` syntax.

**Attributes:**

* `N` (String): Name of the text object
* `X`, `Y` (Number): Text position
* `RZ` (Number, optional): Rotation angle in degrees

**Children Parameters:**

* `Color` (String, T="Text"): Text color
* `Thickness` (Number): Line thickness for text rendering
* `Size` (Number): Text size multiplier
* `Text` (String, T="Text"): The text content (can include `|paramName|` for values)
* `TextAlign` (Number): Alignment (0=left, 1=center, 2=right)
* `IsClosed` (String, T="Text"): Set to "T" for proper rendering

**Children Objects:** 3 `T="Point"` objects defining text box bounds

**Example:**

```xml
<O N="AreaLabel" T="CADDText" X="0" Y="10" RZ="0">
    <P N="Color" V="black" T="Text" />
    <P N="Thickness" V="1" />
    <P N="Size" V="1.5" />
    <P N="IsClosed" V="T" T="Text" />
    <P N="Text" V="Top Reinforcement Area = |round(TopReinfArea,2)| in²" T="Text" />
    <P N="TextAlign" V="0" />
    <O T="Point" X="-20" Y="0" />
    <O T="Point" X="20" Y="0" />
    <O T="Point" X="20" Y="2" />
</O>
```

**Notes:**

* Use `|parameterName|` to embed parameter values in text
* Functions like `round()` can be used: `|round(value,2)|`
* `T="Text"` attribute is required for `Color`, `Text`, and `IsClosed` parameters

***

## CADD Drawing Best Practices

### 1. Conditional Rendering with Guards

Use `Guard` or `GuardX` attributes for conditional visibility of drawing elements.

**Example:**

```xml
<!-- Show only when parameter is enabled -->
<O N="OptionalFeature" T="CADDShape" GuardX="ShowFeature .EQ. 1">
    <O T="Point" X="0" Y="0" />
    <O T="Point" X="10" Y="10" />
    <O T="Point" X="0" Y="10" />
</O>

<!-- Show different versions based on condition -->
<O N="Version1" T="CADDShape" Guard="Version .EQ. 1">
    <!-- Points for version 1 -->
</O>

<O N="Version2" T="CADDShape" Guard="Version .EQ. 2">
    <!-- Points for version 2 -->
</O>
```

**Notes:**

* Use `GuardX` or `Guard` for boolean conditions
* Multiple elements can have complementary guards
* Guards are evaluated dynamically when parameters change

***

### 2. Using Repeat for Arrays

Use `T="Repeat"` to create arrays of objects, such as reinforcement bars in concrete sections.

**Pattern:**

1. Calculate number of elements
2. Create Repeat loop
3. Use loop index `i` to position each element

**Example:**

```xml
<!-- Array of reinforcement bars -->
<O N="RebarArray" T="Repeat" S="0" E="NumBars-1" I="1" CTRL="i" i="0">
    <O T="CADDCircle"
       X="StartX+(i*Spacing)"
       Y="RebarDepth"
       Color="black"
       RZ="0">
        <P N="Radius" V="BarDiameter/2" />
    </O>
</O>
```

**For Symmetric Arrays (Left and Right):**

```xml
<!-- Left side bars -->
<O N="BarsLeft" T="Repeat" S="0" E="NumBars/2-1" I="1" CTRL="i" i="0">
    <O T="CADDCircle" X="-StartX-(i*Spacing)" Y="Depth" Color="black">
        <P N="Radius" V="BarRadius" />
    </O>
</O>

<!-- Right side bars -->
<O N="BarsRight" T="Repeat" S="0" E="NumBars/2-1" I="1" CTRL="i" i="0">
    <O T="CADDCircle" X="StartX+(i*Spacing)" Y="Depth" Color="black">
        <P N="Radius" V="BarRadius" />
    </O>
</O>
```

**Notes:**

* `S` = Start index (usually 0)
* `E` = End index (inclusive)
* `I` = Increment (usually 1)
* `CTRL="i"` defines loop variable name
* `i="0"` sets initial value

***

## Common Coordinate System

**Typical convention for cross-sections:**

* **Y=0** at reference line (often top of section or top flange)
* **Negative Y** goes downward
* **X=0** at section centerline
* **Negative X** to the left, **Positive X** to the right

**Example:**

```xml
<!-- Cross-section with Y=0 at top -->
<!-- Top element: Y = 0 -->
<!-- Middle element: Y = -Depth/2 -->
<!-- Bottom element: Y = -Depth -->
```

**Best Practice:** Document your coordinate system clearly in comments at the start of each CADD drawing.

***

## Summary

**CADD drawings in ParamML:**

* Use `T="CADD"` as container for all drawing elements
* Build shapes with `T="CADDShape"` (closed polygons) and `T="CADDCircle"` (circles)
* Add dimensions with `T="CADDDimensionLine"` (3 points: start, end, offset)
* Add open paths with `T="CADDLine"` (polylines)
* Add labels with `T="CADDText"` (supports parameter values with `|param|`)
* Use `Guard` for conditional rendering based on parameters
* Use `T="Repeat"` for arrays of objects (reinforcement bars, bolt patterns, etc.)
* Define coordinates consistently and document your coordinate system
* All CADD objects update automatically when parameters change

***

**Generated for AI Agents working with OpenBrIM ParamML Code**
