Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 5611) +++ trunk/src/layer.c (revision 5612) @@ -34,6 +34,7 @@ #include "compat_misc.h" #include "undo.h" #include "event.h" +#include "layer_ui.h" pcb_virt_layer_t pcb_virt_layers[] = { {"invisible", PCB_LYT_VIRTUAL + 1, -1, PCB_LYT_VIRTUAL | PCB_LYT_INVIS | PCB_LYT_LOGICAL }, @@ -232,6 +233,9 @@ if ((Layer >= Data->Layer) && (Layer < (Data->Layer + PCB_MAX_LAYER + 2))) return Layer - Data->Layer; + if ((Layer >= pcb_uilayer.array) && (Layer < pcb_uilayer.array + vtlayer_len(&pcb_uilayer))) + return (Layer - pcb_uilayer.array) | PCB_LYT_UI; + return -1; } @@ -302,6 +306,9 @@ { unsigned int res = 0; + if (layer_idx & PCB_LYT_UI) + return PCB_LYT_UI | PCB_LYT_VIRTUAL; + if (layer_idx == pcb_solder_silk_layer) return PCB_LYT_SILK | PCB_LYT_BOTTOM; @@ -547,6 +554,7 @@ case PCB_LYT_ANYPROP: case PCB_LYT_UDRILL: case PCB_LYT_PDRILL: + case PCB_LYT_UI: return -1; /* do not create virtual layers */ case PCB_LYT_INTERN: @@ -620,6 +628,7 @@ case PCB_LYT_ANYPROP: case PCB_LYT_UDRILL: case PCB_LYT_PDRILL: + case PCB_LYT_UI: return -1; /* do not create virtual layers */ case PCB_LYT_INTERN: @@ -930,6 +939,11 @@ { if ((id >= 0) && (id < pcb_max_copper_layer+2)) return &PCB->Data->Layer[id]; + if (id & PCB_LYT_UI) { + id &= ~(PCB_LYT_VIRTUAL | PCB_LYT_UI); + if ((id >= 0) && (id < vtlayer_len(&pcb_uilayer))) + return &(pcb_uilayer.array[id]); + } return NULL; } Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 5611) +++ trunk/src/layer.h (revision 5612) @@ -57,6 +57,8 @@ const char *SelectedColor; pcb_attribute_list_t Attributes; int no_drc; /* whether to ignore the layer when checking the design rules */ + + const char *cookie; /* for UI layers: registration cookie; NULL for unused UI layers */ }; Index: trunk/src/layer_ui.c =================================================================== --- trunk/src/layer_ui.c (revision 5611) +++ trunk/src/layer_ui.c (revision 5612) @@ -26,4 +26,48 @@ /* Virtual layers for UI and debug */ #include "config.h" +#define GVT_DONT_UNDEF #include "layer_ui.h" +#include + +vtlayer_t pcb_uilayer; + +pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const char *color) +{ + int n; + pcb_layer_t *l; + + if (cookie == NULL) + return NULL; + + for(n = 0; n < vtlayer_len(&pcb_uilayer); n++) { + l = &pcb_uilayer.array[n]; + if (l->cookie == NULL) { + l->cookie = cookie; + goto found; + } + } + + l = vtlayer_alloc_append(&pcb_uilayer, 1); +found:; + l->cookie = cookie; + l->Color = color; + l->Name = name; + l->On = 1; + return l; +} + +void pcb_uilayer_free_all_cookie(const char *cookie) +{ + int n; + for(n = 0; n < vtlayer_len(&pcb_uilayer); n++) { + pcb_layer_t *l = &pcb_uilayer.array[n]; + if (l->cookie == cookie) { +#warning TODO: free all objects + l->cookie = NULL; + l->Color = l->Name = NULL; + l->On = 0; + } + } +} + Index: trunk/src/layer_ui.h =================================================================== --- trunk/src/layer_ui.h (revision 5611) +++ trunk/src/layer_ui.h (revision 5612) @@ -26,3 +26,24 @@ /* Virtual layers for UI and debug */ #include "layer.h" + +/* layer vector: Elem=pcb_layer_t *; init=0 */ +#define GVT(x) vtlayer_ ## x +#define GVT_ELEM_TYPE pcb_layer_t +#define GVT_SIZE_TYPE size_t +#define GVT_DOUBLING_THRS 64 +#define GVT_START_SIZE 4 +#define GVT_FUNC +#define GVT_SET_NEW_BYTES_TO 0 +#include +#define GVT_REALLOC(vect, ptr, size) realloc(ptr, size) +#define GVT_FREE(vect, ptr) free(ptr) +#include + +/* list of all UI layers */ +extern vtlayer_t pcb_uilayer; + +pcb_layer_t *pcb_uilayer_alloc(const char *cookie, const char *name, const char *color); +void pcb_uilayer_free_all_cookie(const char *cookie); + +