# tEDAx - camv layer

## purpose

Provides a minimalistic language for describing layers for camv-rnd. The motivation behind this format is to:

- ease development and testing of camv-rnd
- allow the user to make annotations on the GUI that can be saved and loaded
- allow 3rd party tools to generate such annotations in a simple format

## data model

Each layer block describes a single layer. The structure of data described here are closely related to the internal representation camv-rnd has. The layer is drawn using positive (draw) and negative (clear) polarity objects. Order of drawing between two polarity lines are random, but drawing order of polarity blocks is preserved.

Each group block describes a single group of objects with a name unique within the file. Layers can reference a group by name to place it on the layer. Group references can not make any transformation to the group - the purpose of the feature is not supporting footprints or macros, but to group objects together. The grouping affects selection and object highlight.

The coordinate system is a two dimensional cartesian system with 0;0 being the bottom left corner. Angle 0 is y=0;x>0 and positive delta angles are CCW.

## blocks

Layer block type is "camv_layer", version is "v1". The unique identifier is the user visible name of the layer (a single file may normally contain multiple layers). A layer block contains layer properties and drawing primitives.

Group block type is "camv_grp", version is "v1". The unique identifier is used for referencing the group from layers. A group block contains drawing primitives (other than grp) and may contain the unit line from layer properties. The group block must precede any reference to the group. Group polarity is always inherited from the layer that is drawing the group, the group can not change polarity.

## Layer properties

command | parameter names | explanation
--- | --- | ---
color | #rrggbb | Specify preferred/default layer color. camv-rnd will use this color for the layer after load. Six hexadecimal digits prefixed with a hashmark (#). If color is present, it must precede the any polarity line within the layer block. There can be at most one color line in a layer block.
unit | u | Switch units to u, which is m, mm, inch or mil. Any new layer or group starts with unit mm. The unit line can be used multiple times within a layer description: the effect of the line lasts until a new unit line is written or until the end of the layer or group block.
polarity | p | Switch polarity to p, which is either draw or clear. Any new layer starts with polarity draw. The polarity line can be used multiple times within a layer description: the effect of the line lasts until a new polarity line is written or until the end of the layer block.

## Drawing primitives

command | parameter names | explanation
--- | --- | ---
arc | cx cy r th start delta | Draw an arc using a circular pen of diameter th. Coordinates cx and cy are the center of the arc that has a (centerline) radius of r. Arguments start and delta determine the angle span.
line | x1 y1 x2 y2 th | Draw an arc using a circular pen of diameter th, from x1;y1 to x2;y2 (centerline coordinates).
poly | x1 y1 x2 y2 ... xN yN | Draw a filled polygon with a zero diameter pen, using coordinate pairs addressing vertices (corners) of the polygon. Each vertex is listed only once (the last vertex does not need to match the first). The polygon can not intersect itself, may not contain holes and has to have at least 3 vertices.

poly

x1 y1 x2 y2 ... xN yN more below

Same as the above poly, except the polygon is not drawn immediately but a subsequent poly command is expected and coords appended from there. This is to overcome the line length limitation of tedax: a large polygon will use one or more poly lines ending in "more blow" with the last poly line ending in coords. This last line will terminate the coord list and close the polygon.

grp | n | Place the group named n defined in a group block.

## Example

    tEDAx v1

    begin camv_grp v1 arrow1
    	line 10 10 15 10 1
    	line 15 10 13 8 1
    	line 15 10 13 12 1
    end camv_grp

    begin camv_layer v1 pcb\ design\ errors
    	color #ff0000
    	arc 14 11 3 0.5 -20 150
    	poly 20 20 21 21 22 25
    	unit mil
    	grp arrow1
    	line 350 350 550 550 30
    	polarity clear
    	line 350 340 550 560 5
    end camv_layer

Note: despite the "unit mil" line in the layer, arrow1 is created using mm unit because the group has its own unit context that is set to mm when the group is parsed.