Index: trunk/src/obj_arc.c =================================================================== --- trunk/src/obj_arc.c (revision 9000) +++ trunk/src/obj_arc.c (revision 9001) @@ -54,8 +54,7 @@ new_obj = calloc(sizeof(pcb_arc_t), 1); new_obj->type = PCB_OBJ_ARC; - new_obj->parent_type = PCB_PARENT_LAYER; - new_obj->parent.layer = layer; + PCB_SET_PARENT(new_obj, layer, layer); arclist_append(&layer->Arc, new_obj); return new_obj; @@ -66,8 +65,7 @@ pcb_arc_t *arc = calloc(sizeof(pcb_arc_t), 1); arc->type = PCB_OBJ_ARC; - arc->parent_type = PCB_PARENT_ELEMENT; - arc->parent.element = Element; + PCB_SET_PARENT(arc, element, Element); arclist_append(&Element->Arc, arc); return arc; @@ -232,8 +230,7 @@ Layer->arc_tree = pcb_r_create_tree(NULL, 0, 0); pcb_r_insert_entry(Layer->arc_tree, (pcb_box_t *) Arc, 0); Arc->type = PCB_OBJ_ARC; - Arc->parent_type = PCB_PARENT_LAYER; - Arc->parent.layer = Layer; + PCB_SET_PARENT(Arc, layer, Layer); } @@ -317,9 +314,7 @@ pcb_r_insert_entry(lay->arc_tree, (pcb_box_t *) arc, 0); pcb_poly_clear_from_poly(ctx->buffer.dst, PCB_TYPE_ARC, lay, arc); - arc->type = PCB_OBJ_ARC; - arc->parent_type = PCB_PARENT_LAYER; - arc->parent.layer = lay; + PCB_SET_PARENT(arc, layer, lay); return (arc); } @@ -534,9 +529,7 @@ Destination->arc_tree = pcb_r_create_tree(NULL, 0, 0); pcb_r_insert_entry(Destination->arc_tree, (pcb_box_t *) arc, 0); - arc->type = PCB_OBJ_ARC; - arc->parent_type = PCB_PARENT_LAYER; - arc->parent.layer = Destination; + PCB_SET_PARENT(arc, layer, Destination); return arc; } @@ -574,10 +567,7 @@ { pcb_r_delete_entry(Layer->arc_tree, (pcb_box_t *) Arc); - Arc->type = PCB_OBJ_ARC; - Arc->parent_type = PCB_PARENT_INVALID; - Arc->parent.any = NULL; - + PCB_CLEAR_PARENT(Arc); pcb_arc_free(Arc); return NULL; Index: trunk/src/obj_common.h =================================================================== --- trunk/src/obj_common.h (revision 9000) +++ trunk/src/obj_common.h (revision 9001) @@ -82,7 +82,23 @@ pcb_element_t *element; }; +#define PCB_PARENT_TYPENAME_layer PCB_PARENT_LAYER +#define PCB_PARENT_TYPENAME_data PCB_PARENT_DATA +#define PCB_PARENT_TYPENAME_element PCB_PARENT_ELEMENT +#define PCB_SET_PARENT(obj, ptype, parent_ptr) \ + do { \ + obj->parent_type = PCB_PARENT_TYPENAME_ ## ptype; \ + obj->parent.ptype = parent_ptr; \ + } while(0) + +#define PCB_CLEAR_PARENT(obj) \ + do { \ + obj->parent_type = PCB_PARENT_INVALID; \ + obj->parent.any = NULL; \ + } while(0) + + /* point and box type - they are so common everything depends on them */ struct pcb_point_s { /* a line/polygon point */ pcb_coord_t X, Y, X2, Y2; /* so Point type can be cast as pcb_box_t */ Index: trunk/src/obj_elem.c =================================================================== --- trunk/src/obj_elem.c (revision 9000) +++ trunk/src/obj_elem.c (revision 9001) @@ -65,8 +65,7 @@ new_obj = calloc(sizeof(pcb_element_t), 1); new_obj->type = PCB_OBJ_ELEMENT; - new_obj->parent_type = PCB_PARENT_DATA; - new_obj->parent.data = data; + PCB_SET_PARENT(new_obj, data, data); elementlist_append(&data->Element, new_obj); @@ -117,8 +116,7 @@ pcb_line_t *line = calloc(sizeof(pcb_line_t), 1); line->type = PCB_OBJ_ELINE; - line->parent_type = PCB_PARENT_ELEMENT; - line->parent.element = Element; + PCB_SET_PARENT(line, element, Element); linelist_append(&Element->Line, line); Index: trunk/src/obj_line.c =================================================================== --- trunk/src/obj_line.c (revision 9000) +++ trunk/src/obj_line.c (revision 9001) @@ -58,8 +58,7 @@ new_obj = calloc(sizeof(pcb_line_t), 1); new_obj->type = PCB_OBJ_LINE; - new_obj->parent_type = PCB_PARENT_LAYER; - new_obj->parent.layer = layer; + PCB_SET_PARENT(new_obj, layer, layer); linelist_append(&layer->Line, new_obj); Index: trunk/src/obj_pad.c =================================================================== --- trunk/src/obj_pad.c (revision 9000) +++ trunk/src/obj_pad.c (revision 9001) @@ -53,8 +53,7 @@ new_obj = calloc(sizeof(pcb_pad_t), 1); new_obj->type = PCB_OBJ_PAD; - new_obj->parent_type = PCB_PARENT_ELEMENT; - new_obj->parent.element = element; + PCB_SET_PARENT(new_obj, element, element); padlist_append(&element->Pad, new_obj); Index: trunk/src/obj_pinvia.c =================================================================== --- trunk/src/obj_pinvia.c (revision 9000) +++ trunk/src/obj_pinvia.c (revision 9001) @@ -54,8 +54,7 @@ new_obj = calloc(sizeof(pcb_pin_t), 1); new_obj->type = PCB_OBJ_VIA; - new_obj->parent_type = PCB_PARENT_DATA; - new_obj->parent.data = data; + PCB_SET_PARENT(new_obj, data, data); pinlist_append(&data->Via, new_obj); @@ -75,8 +74,7 @@ new_obj = calloc(sizeof(pcb_pin_t), 1); new_obj->type = PCB_OBJ_PIN; - new_obj->parent_type = PCB_PARENT_ELEMENT; - new_obj->parent.element = element; + PCB_SET_PARENT(new_obj, element, element); pinlist_append(&element->Pin, new_obj); Index: trunk/src/obj_poly.c =================================================================== --- trunk/src/obj_poly.c (revision 9000) +++ trunk/src/obj_poly.c (revision 9001) @@ -59,8 +59,7 @@ new_obj = calloc(sizeof(pcb_polygon_t), 1); new_obj->type = PCB_OBJ_POLYGON; - new_obj->parent_type = PCB_PARENT_LAYER; - new_obj->parent.layer = layer; + PCB_SET_PARENT(new_obj, layer, layer); polylist_append(&layer->Polygon, new_obj); Index: trunk/src/obj_rat.c =================================================================== --- trunk/src/obj_rat.c (revision 9000) +++ trunk/src/obj_rat.c (revision 9001) @@ -57,8 +57,7 @@ new_obj = calloc(sizeof(pcb_rat_t), 1); new_obj->type = PCB_OBJ_RAT; - new_obj->parent_type = PCB_PARENT_DATA; - new_obj->parent.data = data; + PCB_SET_PARENT(new_obj, data, data); ratlist_append(&data->Rat, new_obj); Index: trunk/src/obj_text.c =================================================================== --- trunk/src/obj_text.c (revision 9000) +++ trunk/src/obj_text.c (revision 9001) @@ -58,8 +58,7 @@ new_obj = calloc(sizeof(pcb_text_t), 1); new_obj->type = PCB_OBJ_TEXT; - new_obj->parent_type = PCB_PARENT_LAYER; - new_obj->parent.layer = layer; + PCB_SET_PARENT(new_obj, layer, layer); textlist_append(&layer->Text, new_obj);