Index: trunk/src/change.c =================================================================== --- trunk/src/change.c (revision 31210) +++ trunk/src/change.c (revision 31211) @@ -38,6 +38,7 @@ #include "draw.h" #include "select.h" #include "undo.h" +#include "thermal.h" #include #include "obj_pstk_op.h" #include "obj_subc_parent.h" @@ -126,12 +127,12 @@ static pcb_opfunc_t ChangeThermalFunctions = { NULL, /* common_pre */ NULL, /* common_post */ + pcb_anyop_change_thermal, /* line */ NULL, + pcb_anyop_change_thermal, /* poly */ NULL, NULL, - NULL, - NULL, - NULL, + NULL, /* arc */ NULL, /* gfx */ NULL, NULL, Index: trunk/src/obj_common.c =================================================================== --- trunk/src/obj_common.c (revision 31210) +++ trunk/src/obj_common.c (revision 31211) @@ -448,3 +448,4 @@ return &obj->thermal; } + Index: trunk/src/thermal.c =================================================================== --- trunk/src/thermal.c (revision 31210) +++ trunk/src/thermal.c (revision 31211) @@ -29,7 +29,11 @@ #include "thermal.h" #include +#include #include "data.h" +#include "draw.h" +#include "undo.h" +#include "obj_common.h" #include "obj_pstk.h" #include "obj_pstk_inlines.h" #include "obj_pinvia_therm.h" @@ -36,6 +40,8 @@ #include "polygon.h" #include "funchash_core.h" +static const char core_thermal_cookie[] = "core/thermal.c"; + rnd_cardinal_t pcb_themal_style_new2old(unsigned char t) { switch(t) { @@ -859,3 +865,83 @@ return NULL; } + +/*** undoable thermal change ***/ +typedef struct { + pcb_board_t *pcb; + pcb_any_obj_t *obj; + unsigned char shape; +} undo_anyobj_thermal_t; + +static int undo_anyobj_thermal_swap(void *udata) +{ + undo_anyobj_thermal_t *t = udata; + unsigned char old, *th = pcb_obj_common_get_thermal(t->obj, 0, 1); + + if (th != NULL) { + pcb_poly_restore_to_poly(t->pcb->Data, t->obj->type, t->obj->parent.layer, t->obj); + + old = *th; + *th = t->shape; + t->shape = old; + + pcb_poly_clear_from_poly(t->pcb->Data, t->obj->type, t->obj->parent.layer, t->obj); + pcb_draw_invalidate(t->obj); + } + return 0; +} + +static void undo_anyobj_thermal_print(void *udata, char *dst, size_t dst_len) +{ + undo_anyobj_thermal_t *t = udata; + rnd_snprintf(dst, dst_len, "anyobj_thermal: #%ld %d", t->obj->ID, t->shape); +} + +static const uundo_oper_t undo_anyobj_thermal = { + core_thermal_cookie, + NULL, /* free */ + undo_anyobj_thermal_swap, + undo_anyobj_thermal_swap, + undo_anyobj_thermal_print +}; + + +int pcb_anyobj_set_thermal(pcb_any_obj_t *obj, unsigned char shape, int undoable) +{ + undo_anyobj_thermal_t *t; + pcb_board_t *pcb = NULL; + + if (obj->type == PCB_OBJ_PSTK) + return -1; /* needs a layer */ + + if (undoable) { + assert(obj->parent_type == PCB_PARENT_LAYER); + pcb = pcb_data_get_top(obj->parent.layer->parent.data); + } + + if (!undoable || (pcb == NULL)) { + unsigned char *th = pcb_obj_common_get_thermal(obj, 0, 1); + if (th != NULL) + *th = shape; + return 0; + } + + t = pcb_undo_alloc(pcb, &undo_anyobj_thermal, sizeof(undo_anyobj_thermal_t)); + t->pcb = pcb; + t->obj = obj; + t->shape = shape; + undo_anyobj_thermal_swap(t); + return 0; +} + +void *pcb_anyop_change_thermal(pcb_opctx_t *ctx, pcb_any_obj_t *obj) +{ + if (PCB_FLAG_TEST(PCB_FLAG_LOCK, obj)) + return NULL; + + if (pcb_anyobj_set_thermal(obj, ctx->chgtherm.style, 1) != 0) + return NULL; + + return obj; +} + Index: trunk/src/thermal.h =================================================================== --- trunk/src/thermal.h (revision 31210) +++ trunk/src/thermal.h (revision 31211) @@ -28,6 +28,7 @@ #define PCB_THERMAL_H #include "obj_common.h" +#include "operation.h" #include "layer.h" #include @@ -62,5 +63,7 @@ unsigned char pcb_themal_style_old2new(rnd_cardinal_t t); rnd_cardinal_t pcb_themal_style_new2old(unsigned char t); +void *pcb_anyop_change_thermal(pcb_opctx_t *ctx, pcb_any_obj_t *ps); + #endif