## CAM support

The purpose of the CAM support is to provide an unified interface to export a a board in different file formats using different exporter plugins. The interface consists of a CLI layer (each export plugin's "cam" option) and an optional GUI (the CAM plugin).

### CAM export support in other plugins

Each CAM-plugin-compatible exporter plugin offers an option called "cam". The syntax and capabilities are the same for all exporter's cam option.

The syntax is:

    outfile=layergrp[,layergrp,...]

where:

- outfile is the output file name template that substitutes %%:
  - %name% is substituted with the layer group name
  - %base% is substituted with the base name of the output file path (the file name without directories)
  - %top_offs% is substituted with the layer group offset from the top (top layer group being 0); only layer groups with the same material considered
  - %bot_offs% is substituted with the layer group offset from the bottom (bottom layer group being 0); only layer groups with the same material considered
- layergrp: one or more layer group definitions separated by comma (see below)
- optionally a list of exporter options in the same format as on direct command line (e.g. --verbose); when there's overlap on any state/definition between opts and CAM operation, the effect of the opt is ignored

Syntax of the layer group definition:

- @layername (e.g. "@top_copper" if the group's name is top_copper)
- location-material (e.g. "top-copper" for any layer group that is copper and is on the top side)
- type[-type...] (more generally: a list of layer type flags)
- type:offs (e.g. "copper:+2" means the second copper layer group from the top, "copper:-3" means the third copper layer group from the bottom; offs is counted from 1, +1 meaning top outer layer, -1 meaning bottom outer layer)
- plus an optional list of supplements in paranthesis

When supplements are specified, it's a comma separated list of key=value pairs. Available supplements are:

- purpose: specify matching layer group purpose field
- bloat: bloat or shrink objects by the specified value (e.g. 1mm)
- (TODO: supplement for inversion)

Examples:

directive | explanation
--- | ---
bot.gbr=@bottom_copper,@bottom_silk | export layer groups called bottom_copper and bottom_silk (by group name)
asm=top-assy | export the top assembly group, by type
fabrication.ps=fab | export any fab layer group, by type
gnd=copper:2 | export the second copper layer group from the top (the first internal copper layer group under the top copper layer group, if it is a multilayer board; for 2 layer boards this will be the bottom copper layer group)
gnd=intern-copper:1 | similar to the above, but addresses the first internal copper layer group explicitly so it can not end up being the bottom copper layer group
pwr=copper:-2 | export the second copper layer group from the bottom (the first internal copper layer group above the bottom copper layer group, if it is a multilayer board; for 2 layer boards this will be the top copper layer group)
gnd=intern-copper:-1 | similar to the above, but addresses the last internal copper layer group explicitly so it can not end up being the top copper layer group
pst.gbr=top-paste(bloat=0.1mm),bottom-paste(bloat=0.1mm) | export the top and bottom paste groups in the same file with all objects bloated up by 0.1mm
plated_drills.cnc=virtual(purpose=pdrill) | export plated drilled holes (padstack side effects, but no slots)
unplated_drills.cnc=virtual(purpose=udrill) | export unplated drilled holes (padstack side effects, but no slots)

If multiple layer groups match a layergrp specification, all matching layer groups are exported. If the file name is a static string, they are all merged. If the file name is templated, it is possible to export the layer groups in multiple files. For example:

directive | explanation
--- | ---
copper.gbr=copper | export all copper layers to copper.gbr
copper-%top_offs%.gbr=copper | export all copper layers to numbered copper-N.gbr files where N is the offset from the top side, starting from 0 (for top copper)
copper-%name%.gbr=copper | export all copper layers to numbered copper-N.gbr files where N is the full name of the group being exported

### CAM plugin

The CAM plugin is a way to manage output "jobs": collections of cam export settings for reproducing export packages in various formats.

...

A job is a script that contains zero or more export directives, separated by semicolons or newlines. An export directive is one of these:

    desc text
    plugin name [--option value] [--option value] ...
    write outfile=layergrp[,layergrp,...]

desc is a free form one-liner that describes what the job is for. Multiple desc directives may be present (to bypass the limitation that the text can not contain newlines).

The plugin directive selects a plugin and sets plugin specific options. The plugin and options are active until the next plugin directive or the end of the script. The first outfile directive must be preceeded by a plugin directive.

The write directive argument has the same syntax as the cam argument for each cam-capable exporter, see above. Each write is a call to an exporter the same way as if pcb-rnd was called with --cam and -x with the exporter and options taken from the last plugin directive.

For example, the following config tree defines a job called doc_png that generates two 600 DPI images from the sides of the board, copper and silk combined, all in the doc/ dir (that is created if necessary):

    li:pcb-rnd-conf-v1 {
    	ha:overwrite {
    		ha:plugins {
    			ha:cam {
    				li:jobs {
    					doc_png {
    						desc export top and bottom copper and silk in 600 DPI pngs
    						plugin png --dpi 600
    						write top.png=top-copper,top-silk
    						write bottom.png=bottom-copper,bottom-silk
    					}
    				}
    			}
    		}
    	}
    }

Once the above subtree is loaded in the config, the following action triggers the export:

    cam(call, doc_png)

### Tips for using with various exporters

When exporting to ps, consider using the --no-show-toc. It is possible to combine multiple layers (e.g. top silk and top copper, which may be useful for a single-layer board) using the --single-page option.

The plugin field has the same values command line -x has. The list of currently available exporter names can be acquired by running

    pcb-rnd -x

Note: this list contains all exporter plugins currently available (depends on your configure time options and plugin availability). Some export plugins can not do per layer exporting and those will not support CAM exporting either.