Index: trunk/src/buffer.c =================================================================== --- trunk/src/buffer.c (revision 22623) +++ trunk/src/buffer.c (revision 22624) @@ -636,7 +636,7 @@ continue; } - destlayer = pcb_loose_subc_layer(PCB, destlayer); + destlayer = pcb_loose_subc_layer(PCB, destlayer, pcb_true); if (destlayer->meta.real.vis) { PCB_LINE_LOOP(sourcelayer); Index: trunk/src/obj_subc.c =================================================================== --- trunk/src/obj_subc.c (revision 22623) +++ trunk/src/obj_subc.c (revision 22624) @@ -334,7 +334,7 @@ return poly; } -pcb_layer_t *pcb_loose_subc_layer(pcb_board_t *pcb, pcb_layer_t *layer) +pcb_layer_t *pcb_loose_subc_layer(pcb_board_t *pcb, pcb_layer_t *layer, pcb_bool alloc) { pcb_subc_t *sc; int n; @@ -353,6 +353,15 @@ if (l->meta.bound.real == layer) return l; } + + /* the subc does not have that layer */ + if (alloc) { + pcb_layer_t *nlayer = &sc->data->Layer[sc->data->LayerN]; + sc->data->LayerN++; + pcb_layer_real2bound(nlayer, layer, 1); + return nlayer; + } + return layer; } Index: trunk/src/obj_subc.h =================================================================== --- trunk/src/obj_subc.h (revision 22623) +++ trunk/src/obj_subc.h (revision 22624) @@ -131,8 +131,9 @@ void *pcb_subc_remove(pcb_subc_t *sc); /* In board mode return brd_layer; in footprint edit mode, return the subcircuit - layer that matches brd_layer or brd_layer if not found. */ -pcb_layer_t *pcb_loose_subc_layer(pcb_board_t *pcb, pcb_layer_t *brd_layer); + layer that matches brd_layer. If not found, either allocate it within + the subc (if alloc is true) or return the brd_layer. */ +pcb_layer_t *pcb_loose_subc_layer(pcb_board_t *pcb, pcb_layer_t *brd_layer, pcb_bool alloc); /* Returns whether there's no object in the subc */ pcb_bool pcb_subc_is_empty(pcb_subc_t *subc); Index: trunk/src/polygon.c =================================================================== --- trunk/src/polygon.c (revision 22623) +++ trunk/src/polygon.c (revision 22624) @@ -1519,7 +1519,7 @@ */ void pcb_polygon_copy_attached_to_layer(void) { - pcb_layer_t *layer = pcb_loose_subc_layer(PCB, CURRENT); + pcb_layer_t *layer = pcb_loose_subc_layer(PCB, CURRENT, pcb_true); pcb_poly_t *polygon; int saveID; Index: trunk/src/route.c =================================================================== --- trunk/src/route.c (revision 22623) +++ trunk/src/route.c (revision 22624) @@ -422,7 +422,7 @@ for(i = 0; i < p_route->size; i++) { pcb_route_object_t const *p_obj = &p_route->objects[i]; - pcb_layer_t *layer = pcb_loose_subc_layer(PCB, pcb_get_layer(PCB->Data, p_obj->layer)); + pcb_layer_t *layer = pcb_loose_subc_layer(PCB, pcb_get_layer(PCB->Data, p_obj->layer), pcb_true); switch (p_obj->type) { case PCB_OBJ_LINE: @@ -520,7 +520,7 @@ for(i = 0; i < p_route->size; i++) { pcb_route_object_t const *p_obj = &p_route->objects[i]; - pcb_layer_t *layer = pcb_loose_subc_layer(PCB, pcb_get_layer(PCB->Data, p_obj->layer)); + pcb_layer_t *layer = pcb_loose_subc_layer(PCB, pcb_get_layer(PCB->Data, p_obj->layer), pcb_true); switch (p_obj->type) { case PCB_OBJ_ARC: Index: trunk/src/tool_arc.c =================================================================== --- trunk/src/tool_arc.c (revision 22623) +++ trunk/src/tool_arc.c (revision 22624) @@ -101,7 +101,7 @@ dir = (PCB_SGNZ(wx) == PCB_SGNZ(wy)) ? -90 : 90; wy = wx; } - if (coord_abs(wy) > 0 && (arc = pcb_arc_new(pcb_loose_subc_layer(PCB, CURRENT), + if (coord_abs(wy) > 0 && (arc = pcb_arc_new(pcb_loose_subc_layer(PCB, CURRENT, pcb_true), pcb_crosshair.AttachedBox.Point2.X, pcb_crosshair.AttachedBox.Point2.Y, coord_abs(wy), Index: trunk/src/tool_line.c =================================================================== --- trunk/src/tool_line.c (revision 22623) +++ trunk/src/tool_line.c (revision 22624) @@ -248,7 +248,7 @@ if ((pcb_crosshair.AttachedLine.Point1.X != pcb_crosshair.AttachedLine.Point2.X || pcb_crosshair.AttachedLine.Point1.Y != pcb_crosshair.AttachedLine.Point2.Y) && (line = - pcb_line_new_merge(pcb_loose_subc_layer(PCB, CURRENT), + pcb_line_new_merge(pcb_loose_subc_layer(PCB, CURRENT, pcb_true), pcb_crosshair.AttachedLine.Point1.X, pcb_crosshair.AttachedLine.Point1.Y, pcb_crosshair.AttachedLine.Point2.X, @@ -293,7 +293,7 @@ } if (conf_core.editor.line_refraction && (pcb_tool_note.X != pcb_crosshair.AttachedLine.Point2.X || pcb_tool_note.Y != pcb_crosshair.AttachedLine.Point2.Y) && (line = - pcb_line_new_merge(pcb_loose_subc_layer(PCB, CURRENT), + pcb_line_new_merge(pcb_loose_subc_layer(PCB, CURRENT, pcb_true), pcb_crosshair.AttachedLine.Point2.X, pcb_crosshair.AttachedLine.Point2.Y, pcb_tool_note.X, pcb_tool_note.Y, Index: trunk/src/tool_rectangle.c =================================================================== --- trunk/src/tool_rectangle.c (revision 22623) +++ trunk/src/tool_rectangle.c (revision 22624) @@ -64,7 +64,7 @@ pcb_crosshair.AttachedBox.Point1.X != pcb_crosshair.AttachedBox.Point2.X && pcb_crosshair.AttachedBox.Point1.Y != pcb_crosshair.AttachedBox.Point2.Y) { pcb_poly_t *polygon; - pcb_layer_t *layer = pcb_loose_subc_layer(PCB, CURRENT); + pcb_layer_t *layer = pcb_loose_subc_layer(PCB, CURRENT, pcb_true); int flags = PCB_FLAG_CLEARPOLY; if (conf_core.editor.full_poly) Index: trunk/src/tool_text.c =================================================================== --- trunk/src/tool_text.c (revision 22623) +++ trunk/src/tool_text.c (revision 22624) @@ -57,7 +57,7 @@ if (pcb_layer_flags(PCB, INDEXOFCURRENT) & PCB_LYT_BOTTOM) flag |= PCB_FLAG_ONSOLDER; - if ((text = pcb_text_new(pcb_loose_subc_layer(PCB, CURRENT), pcb_font(PCB, conf_core.design.text_font_id, 1), pcb_tool_note.X, + if ((text = pcb_text_new(pcb_loose_subc_layer(PCB, CURRENT, pcb_true), pcb_font(PCB, conf_core.design.text_font_id, 1), pcb_tool_note.X, pcb_tool_note.Y, 0, conf_core.design.text_scale, conf_core.design.text_thickness, string, pcb_flag_make(flag))) != NULL) { pcb_undo_add_obj_to_create(PCB_OBJ_TEXT, CURRENT, text, text); pcb_undo_inc_serial();