Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 32974) +++ trunk/src/layer.c (revision 32975) @@ -1115,6 +1115,19 @@ return NULL; } +rnd_layer_id_t pcb_layer2id(pcb_data_t *data, pcb_layer_t *ly) +{ + long lid; + + if (ly == NULL) return -1; + + lid = ly - data->Layer; + if ((lid < 0) || (lid >= data->LayerN)) + return -1; + + return lid; +} + void pcb_layer_link_trees(pcb_layer_t *dst, pcb_layer_t *src) { /* we can't link non-existing trees - make sure src does have the trees initialized */ Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 32974) +++ trunk/src/layer.h (revision 32975) @@ -206,6 +206,9 @@ /* Return the layer pointer (or NULL on invalid or virtual layers) for an id */ pcb_layer_t *pcb_get_layer(pcb_data_t *data, rnd_layer_id_t id); +/* Return the layer ID within data, or -1 if ly is not in data */ +rnd_layer_id_t pcb_layer2id(pcb_data_t *data, pcb_layer_t *ly); + /* Return the name of a layer (real or virtual) or NULL on error NOTE: layer names may not be unique; returns the first case sensitive hit; slow linear search */