Index: trunk/src/obj_poly.c =================================================================== --- trunk/src/obj_poly.c (revision 20164) +++ trunk/src/obj_poly.c (revision 20165) @@ -59,6 +59,24 @@ /*** allocation ***/ +void pcb_poly_reg(pcb_layer_t *layer, pcb_poly_t *poly) +{ + polylist_append(&layer->Polygon, poly); + assert(layer->parent_type == PCB_PARENT_DATA); + pcb_obj_id_reg(layer->parent.data, poly); + PCB_SET_PARENT(poly, layer, layer); +} + +void pcb_poly_unreg(pcb_poly_t *poly) +{ + pcb_layer_t *layer = poly->parent.layer; + assert(poly->parent_type == PCB_PARENT_LAYER); + polylist_remove(poly); + assert(layer->parent_type == PCB_PARENT_DATA); + pcb_obj_id_del(layer->parent.data, poly); + PCB_SET_PARENT(poly, layer, NULL); +} + pcb_poly_t *pcb_poly_alloc(pcb_layer_t * layer) { pcb_poly_t *new_obj; @@ -66,17 +84,16 @@ new_obj = calloc(sizeof(pcb_poly_t), 1); new_obj->type = PCB_OBJ_POLY; new_obj->Attributes.post_change = pcb_obj_attrib_post_change; - PCB_SET_PARENT(new_obj, layer, layer); - polylist_append(&layer->Polygon, new_obj); + pcb_poly_reg(layer, new_obj); return new_obj; } -void pcb_poly_free(pcb_poly_t * data) +void pcb_poly_free(pcb_poly_t *poly) { - polylist_remove(data); - free(data); + pcb_poly_unreg(poly); + free(poly); } /* gets the next slot for a point in a polygon struct, allocates memory if necessary */ @@ -112,6 +129,9 @@ /* frees memory used by a polygon */ void pcb_poly_free_fields(pcb_poly_t * polygon) { + pcb_parent_t parent; + pcb_parenttype_t parent_type; + if (polygon == NULL) return; @@ -122,7 +142,12 @@ pcb_polyarea_free(&polygon->Clipped); pcb_poly_contours_free(&polygon->NoHoles); + /* have to preserve parent info for unreg */ + parent = polygon->parent; + parent_type = polygon->parent_type; reset_obj_mem(pcb_poly_t, polygon); + polygon->parent = parent; + polygon->parent_type = parent_type; } /*** utility ***/ @@ -481,8 +506,8 @@ pcb_r_delete_entry(srcly->polygon_tree, (pcb_box_t *)polygon); - polylist_remove(polygon); - polylist_append(&dstly->Polygon, polygon); + pcb_poly_unreg(polygon); + pcb_poly_reg(dstly, polygon); PCB_FLAG_CLEAR(PCB_FLAG_FOUND, polygon); @@ -490,8 +515,6 @@ dstly->polygon_tree = pcb_r_create_tree(); pcb_r_insert_entry(dstly->polygon_tree, (pcb_box_t *)polygon); - PCB_SET_PARENT(polygon, layer, dstly); - pcb_poly_ppclear(polygon); return polygon; } @@ -689,14 +712,13 @@ pcb_r_delete_entry(Source->polygon_tree, (pcb_box_t *) polygon); pcb_poly_pprestore(polygon); - polylist_remove(polygon); - polylist_append(&Destination->Polygon, polygon); + pcb_poly_unreg(polygon); + pcb_poly_reg(Destination, polygon); if (!Destination->polygon_tree) Destination->polygon_tree = pcb_r_create_tree(); pcb_r_insert_entry(Destination->polygon_tree, (pcb_box_t *) polygon); - PCB_SET_PARENT(polygon, layer, Destination); pcb_poly_ppclear(polygon); return polygon; } Index: trunk/src/obj_poly.h =================================================================== --- trunk/src/obj_poly.h (revision 20164) +++ trunk/src/obj_poly.h (revision 20165) @@ -60,6 +60,9 @@ pcb_cardinal_t *pcb_poly_holeidx_new(pcb_poly_t *Polygon); void pcb_poly_free_fields(pcb_poly_t * polygon); +void pcb_poly_reg(pcb_layer_t *layer, pcb_poly_t *poly); +void pcb_poly_unreg(pcb_poly_t *poly); + void pcb_poly_bbox(pcb_poly_t *Polygon); pcb_poly_t *pcb_poly_new_from_rectangle(pcb_layer_t *Layer, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_coord_t Clearance, pcb_flag_t Flags); pcb_poly_t *pcb_poly_new_from_poly(pcb_layer_t *Layer, pcb_poly_t *src, pcb_coord_t offs, pcb_coord_t Clearance, pcb_flag_t Flags); @@ -74,6 +77,7 @@ void pcb_poly_rotate(pcb_layer_t *layer, pcb_poly_t *poly, pcb_coord_t X, pcb_coord_t Y, double cosa, double sina); void pcb_poly_mirror(pcb_layer_t *layer, pcb_poly_t *polygon, pcb_coord_t y_offs); void pcb_poly_flip_side(pcb_layer_t *layer, pcb_poly_t *polygon); +void pcb_poly_scale(pcb_poly_t *poly, double sx, double sy); void pcb_poly_move(pcb_poly_t *Polygon, pcb_coord_t DX, pcb_coord_t DY); pcb_poly_t *pcb_poly_copy(pcb_poly_t *Dest, pcb_poly_t *Src, pcb_coord_t dx, pcb_coord_t dy); Index: trunk/src/obj_subc.c =================================================================== --- trunk/src/obj_subc.c (revision 20164) +++ trunk/src/obj_subc.c (revision 20165) @@ -497,9 +497,9 @@ } while((poly = polylist_first(&src->Polygon)) != NULL) { - polylist_remove(poly); - polylist_append(&dst->Polygon, poly); - PCB_SET_PARENT(poly, layer, dst); + pcb_poly_unreg(poly); + pcb_poly_reg(dst, poly); + PCB_FLAG_CLEAR(PCB_FLAG_WARN | PCB_FLAG_FOUND | PCB_FLAG_SELECTED, poly); } }