<-- back to the index of Rosetta examples

# animated clock on a UI layer

Create and animate an analog clock on a dedicated UI layer.

## Example implementations

awk

## Explanation, step by step

Animated clock on an UI layer.

### Theory of operation

### Implementation

Load packages the script depends on:

- hid for registering the new exporter;
- layout for unit conversion;
- dialogs for error reporting.

Set up an exporter hid, storing the handle of each object created in a global variable:

- create a hid using hid_create
- add two attributes (fields) to the dialog using hid_add_attribute
- register the new hid using hid_register - this makes it an exporter

Set up global state variables:

- fmt will be a cache for the format selected by the user
- conv is the conversion scale between mm and PCB internal coordinate unit
- channel specifies a file handle or indicates that the output file is open
- green_light indicates that the exporter is drawing the relevant layer

Define a make_gc callback. It is called when a new graphic context is created (e.g. for layers). An exporter is sort of a drawing backend: pcb-rnd sets up gc's and draws on them. The first gc set up should open the output file, the last gc closed should flush/close the file. Define a destroy_gc callback for the latter. GCs are destroyed at the end of the export process. Use global variable channel to make sure the file is open/close only once (see TODO script context ).

Define a set_layer callback that sets green_light to true if layer name is "topasssembly", false otherwise.

Callback fill_circle is the workhorse: check if we have the green light to emit lines, then convert coordinates and diameter to mm and decide what format to use for printing a line for each filled circle.

Finally, bind all four callbacks to exporter events.