Index: trunk/src/board.c =================================================================== --- trunk/src/board.c (revision 29045) +++ trunk/src/board.c (revision 29046) @@ -45,6 +45,8 @@ pcb_board_t *PCB; +static const char core_board_cookie[] = "core/board"; + void pcb_board_free(pcb_board_t * pcb) { int i; @@ -259,10 +261,10 @@ return pcb_true; } -void pcb_board_resize(pcb_coord_t Width, pcb_coord_t Height) +static void pcb_board_resize_(pcb_board_t *pcb, pcb_coord_t Width, pcb_coord_t Height) { - PCB->hidlib.size_x = Width; - PCB->hidlib.size_y = Height; + pcb->hidlib.size_x = Width; + pcb->hidlib.size_y = Height; /* crosshair range is different if pastebuffer-mode * is enabled @@ -276,9 +278,58 @@ else pcb_crosshair_set_range(0, 0, Width, Height); - pcb_board_changed(0); + if (pcb == PCB) + pcb_board_changed(0); } +/*** undoable board resize ***/ + +typedef struct { + pcb_board_t *pcb; + pcb_coord_t w, h; +} undo_board_size_t; + +static int undo_board_size_swap(void *udata) +{ + undo_board_size_t *s = udata; + pcb_coord_t oldw = s->pcb->hidlib.size_x, oldh = s->pcb->hidlib.size_y; + pcb_board_resize_(s->pcb, s->w, s->h); + s->w = oldw; + s->h = oldh; + return 0; +} + +static void undo_board_size_print(void *udata, char *dst, size_t dst_len) +{ + undo_board_size_t *s = udata; + pcb_snprintf(dst, dst_len, "board_size: %mmx%mm", s->w, s->h); +} + +static const uundo_oper_t undo_board_size = { + core_board_cookie, + NULL, /* free */ + undo_board_size_swap, + undo_board_size_swap, + undo_board_size_print +}; + +void pcb_board_resize(pcb_coord_t width, pcb_coord_t height, int undoable) +{ + undo_board_size_t *s; + + if (!undoable) { + pcb_board_resize_(PCB, width, height); + return; + } + + s = pcb_undo_alloc(PCB, &undo_board_size, sizeof(undo_board_size_t)); + s->pcb = PCB; + s->w = width; + s->h = height; + undo_board_size_swap(s); +} + + void pcb_board_remove(pcb_board_t *Ptr) { pcb_undo_clear_list(pcb_true); Index: trunk/src/board.h =================================================================== --- trunk/src/board.h (revision 29045) +++ trunk/src/board.h (revision 29046) @@ -136,7 +136,7 @@ /* changes the maximum size of a layout, notifies the GUI * and adjusts the cursor confinement box */ -void pcb_board_resize(pcb_coord_t Width, pcb_coord_t Height); +void pcb_board_resize(pcb_coord_t Width, pcb_coord_t Height, int undoable); /* free the board and remove its undo list */ Index: trunk/src/plug_io.c =================================================================== --- trunk/src/plug_io.c (revision 29045) +++ trunk/src/plug_io.c (revision 29046) @@ -547,7 +547,7 @@ pcb_crosshair.Y = PCB->hidlib.size_y/2; /* update cursor confinement and output area (scrollbars) */ - pcb_board_resize(PCB->hidlib.size_x, PCB->hidlib.size_y); + pcb_board_resize(PCB->hidlib.size_x, PCB->hidlib.size_y, 0); } /* have to be called after pcb_board_resize() so vis update is after a board changed update */ @@ -733,7 +733,7 @@ res = -1; } else - pcb_board_resize(b.X2*1.5, b.Y2*1.5); + pcb_board_resize(b.X2*1.5, b.Y2*1.5, 0); } } return res; Index: trunk/src_plugins/autocrop/autocrop.c =================================================================== --- trunk/src_plugins/autocrop/autocrop.c (revision 29045) +++ trunk/src_plugins/autocrop/autocrop.c (revision 29046) @@ -2,9 +2,9 @@ * COPYRIGHT * * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2016 Tibor 'Igor2' Palinkas + * Copyright (C) 2016,2020 Tibor 'Igor2' Palinkas * - * This module, debug, was written and is Copyright (C) 2016 by Tibor Palinkas + * This module, debug, was written and is Copyright (C) by Tibor Palinkas * this module is also subject to the GNU GPL as described below * * This program is free software; you can redistribute it and/or modify @@ -60,7 +60,7 @@ pcb_draw_inhibit_inc(); pcb_data_clip_inhibit_inc(PCB->Data); pcb_data_move(PCB->Data, dx, dy); - pcb_board_resize(w, h); + pcb_board_resize(w, h, 0); pcb_data_clip_inhibit_dec(PCB->Data, 1); pcb_draw_inhibit_dec(); Index: trunk/src_plugins/dialogs/dlg_pref_sizes.c =================================================================== --- trunk/src_plugins/dialogs/dlg_pref_sizes.c (revision 29045) +++ trunk/src_plugins/dialogs/dlg_pref_sizes.c (revision 29046) @@ -47,7 +47,7 @@ ctx->sizes.lock++; if ((PCB->hidlib.size_x != ctx->dlg[ctx->sizes.wwidth].val.crd) || (PCB->hidlib.size_y != ctx->dlg[ctx->sizes.wheight].val.crd)) - pcb_board_resize(ctx->dlg[ctx->sizes.wwidth].val.crd, ctx->dlg[ctx->sizes.wheight].val.crd); + pcb_board_resize(ctx->dlg[ctx->sizes.wwidth].val.crd, ctx->dlg[ctx->sizes.wheight].val.crd, 0); ctx->sizes.lock--; } Index: trunk/src_plugins/io_hyp/parser.c =================================================================== --- trunk/src_plugins/io_hyp/parser.c (revision 29045) +++ trunk/src_plugins/io_hyp/parser.c (revision 29046) @@ -655,7 +655,7 @@ /* resize if board too small */ if ((width > PCB->hidlib.size_x) || (height > PCB->hidlib.size_y)) - pcb_board_resize(width, height); + pcb_board_resize(width, height, 0); return; Index: trunk/src_plugins/propedit/propsel.c =================================================================== --- trunk/src_plugins/propedit/propsel.c (revision 29045) +++ trunk/src_plugins/propedit/propsel.c (revision 29046) @@ -378,7 +378,7 @@ static int brd_resize(pcb_coord_t w, pcb_coord_t h) { - pcb_board_resize(w, h); + pcb_board_resize(w, h, 0); return 1; }