Index: trunk/src/layer.c =================================================================== --- trunk/src/layer.c (revision 8942) +++ trunk/src/layer.c (revision 8943) @@ -369,6 +369,16 @@ PCB_FLAG_THERM_ASSIGN(ni, 0, pin); } + +static void swap_one_thermal(int lid1, int lid2, pcb_pin_t * pin) +{ + int was_on_l1 = !!PCB_FLAG_THERM_GET(lid1, pin); + int was_on_l2 = !!PCB_FLAG_THERM_GET(lid2, pin); + + PCB_FLAG_THERM_ASSIGN(lid2, was_on_l1, pin); + PCB_FLAG_THERM_ASSIGN(lid1, was_on_l2, pin); +} + static void move_all_thermals(int old_index, int new_index) { PCB_VIA_LOOP(PCB->Data); @@ -571,6 +581,51 @@ return 0; } +int pcb_layer_swap(pcb_layer_id_t lid1, pcb_layer_id_t lid2) +{ + pcb_layer_t l1tmp, l2tmp; + pcb_layergrp_id_t gid; + + if (lid1 == lid2) + return 0; + + printf("SWAP: %d %d\n", lid1, lid2); + + layer_move(&l1tmp, &PCB->Data->Layer[lid1]); + layer_move(&l2tmp, &PCB->Data->Layer[lid2]); + + layer_move(&PCB->Data->Layer[lid1], &l2tmp); + layer_move(&PCB->Data->Layer[lid2], &l1tmp); + + PCB_VIA_LOOP(PCB->Data); + { + swap_one_thermal(lid1, lid2, via); + } + PCB_END_LOOP; + + PCB_PIN_ALL_LOOP(PCB->Data); + { + swap_one_thermal(lid1, lid2, pin); + } + PCB_ENDALL_LOOP; + + for(gid = 0; gid < pcb_max_group(PCB); gid++) { + pcb_layer_group_t *g = &PCB->LayerGroups.grp[gid]; + int n; + + for(n = 0; n < g->len; n++) { + if (g->lid[n] == lid1) + g->lid[n] = lid2; + else if (g->lid[n] == lid2) + g->lid[n] = lid1; + } + } + + return 0; +} + + + const char *pcb_layer_name(pcb_layer_id_t id) { if (id < 0) Index: trunk/src/layer.h =================================================================== --- trunk/src/layer.h (revision 8942) +++ trunk/src/layer.h (revision 8943) @@ -150,6 +150,10 @@ { \ pcb_layer_t *layer = (&data->Layer[(n)]); +/* Swap two layers in PCB->Data; useful only in writing the old .pcb format, + because silk layers must be the last 2 layers there */ +int pcb_layer_swap(pcb_layer_id_t lid1, pcb_layer_id_t lid2); + /************ NEW API - new code should use these **************/ /* Return the layer pointer (or NULL on invalid or virtual layers) for an id */ @@ -216,6 +220,8 @@ int pcb_layer_move(pcb_layer_id_t old_index, pcb_layer_id_t new_index, pcb_layergrp_id_t new_in_grp); + + /* list of virtual layers: these are generated by the draw code but do not have a real layer in the array */ typedef struct pcb_virt_layer_s {