Index: trunk/src/netlist2.c =================================================================== --- trunk/src/netlist2.c (revision 23610) +++ trunk/src/netlist2.c (revision 23611) @@ -614,7 +614,8 @@ /* best connection is 'best' between from 'undone' network bestu; draw the rat */ line = pcb_rat_new(sctx->pcb->Data, -1, best->o1x, best->o1y, best->o2x, best->o2y, best->o1g, best->o2g, - conf_core.appearance.rat_thickness, pcb_no_flags()); + conf_core.appearance.rat_thickness, pcb_no_flags(), + best->o1, best->o2); if (line != NULL) { if (best->dist2 == 0) PCB_FLAG_SET(PCB_FLAG_VIA, line); @@ -860,7 +861,7 @@ target_net = net2; /* create the rat and add terminals in the target_net */ - res = pcb_rat_new(pcb->Data, -1, x1, y1, x2, y2, group1, group2, conf_core.appearance.rat_thickness, pcb_no_flags()); + res = pcb_rat_new(pcb->Data, -1, x1, y1, x2, y2, group1, group2, conf_core.appearance.rat_thickness, pcb_no_flags(), o1, o2); old_len = pcb_termlist_length(&target_net->conns); pcb_net_term_get(target_net, sc1->refdes, o1->term, 1); Index: trunk/src/obj_rat.c =================================================================== --- trunk/src/obj_rat.c (revision 23610) +++ trunk/src/obj_rat.c (revision 23611) @@ -85,12 +85,14 @@ void pcb_rat_free(pcb_rat_t *rat) { pcb_rat_unreg(rat); + free(rat->anchor[0]); + free(rat->anchor[1]); free(rat); } /*** utility ***/ /* creates a new rat-line */ -pcb_rat_t *pcb_rat_new(pcb_data_t *Data, long int id, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_layergrp_id_t group1, pcb_layergrp_id_t group2, pcb_coord_t Thickness, pcb_flag_t Flags) +pcb_rat_t *pcb_rat_new(pcb_data_t *Data, long int id, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_layergrp_id_t group1, pcb_layergrp_id_t group2, pcb_coord_t Thickness, pcb_flag_t Flags, pcb_any_obj_t *anchor1, pcb_any_obj_t *anchor2) { pcb_rat_t *Line; @@ -116,6 +118,12 @@ if (!Data->rat_tree) Data->rat_tree = pcb_r_create_tree(); pcb_r_insert_entry(Data->rat_tree, &Line->BoundingBox); + + if (anchor1 != NULL) + Line->anchor[0] = pcb_obj2idpath(anchor1); + if (anchor2 != NULL) + Line->anchor[1] = pcb_obj2idpath(anchor2); + return Line; } @@ -142,14 +150,42 @@ return changed; } +/*** utility ***/ +pcb_any_obj_t *pcb_rat_anchor_guess(pcb_rat_t *rat, int end, pcb_bool update) +{ + pcb_idpath_t **path = &rat->anchor[!!end]; + pcb_any_obj_t *ao; + + TODO("check if anchor is where the rat line ends"); + TODO("if not, check what's at the end and update"); + + return NULL; +} + +void pcb_rat_all_anchor_guess(pcb_data_t *data) +{ + pcb_rat_t *rat; + gdl_iterator_t it; + ratlist_foreach(&data->Rat, &it, rat) { + pcb_rat_anchor_guess(rat, 0, pcb_true); + pcb_rat_anchor_guess(rat, 1, pcb_true); + } +} + + /*** ops ***/ /* copies a rat-line to paste buffer */ void *pcb_ratop_add_to_buffer(pcb_opctx_t *ctx, pcb_rat_t *Rat) { - return (pcb_rat_new(ctx->buffer.dst, -1, Rat->Point1.X, Rat->Point1.Y, + pcb_rat_t *res = pcb_rat_new(ctx->buffer.dst, -1, Rat->Point1.X, Rat->Point1.Y, Rat->Point2.X, Rat->Point2.Y, Rat->group1, Rat->group2, Rat->Thickness, - pcb_flag_mask(Rat->Flags, PCB_FLAG_FOUND | ctx->buffer.extraflg))); + pcb_flag_mask(Rat->Flags, PCB_FLAG_FOUND | ctx->buffer.extraflg), + NULL, NULL); + + res->anchor[0] = pcb_idpath_dup(Rat->anchor[0]); + res->anchor[1] = pcb_idpath_dup(Rat->anchor[1]); + return res; } /* moves a rat-line between board and buffer */ Index: trunk/src/obj_rat.h =================================================================== --- trunk/src/obj_rat.h (revision 23610) +++ trunk/src/obj_rat.h (revision 23611) @@ -34,11 +34,13 @@ #include #include "obj_common.h" #include "layer_grp.h" +#include "idpath.h" struct pcb_rat_line_s { /* a rat-line */ PCB_ANYLINEFIELDS; pcb_layergrp_id_t group1, group2; /* the layer group each point is on */ - gdl_elem_t link; /* an arc is in a list on a design */ + pcb_idpath_t *anchor[2]; /* endpoint object that were originally connected */ + gdl_elem_t link; /* a rat line is in a list on a design */ }; @@ -49,9 +51,17 @@ void pcb_rat_unreg(pcb_rat_t *rat); /* if id is <= 0, allocate a new id */ -pcb_rat_t *pcb_rat_new(pcb_data_t *Data, long int id, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_layergrp_id_t group1, pcb_layergrp_id_t group2, pcb_coord_t Thickness, pcb_flag_t Flags); +pcb_rat_t *pcb_rat_new(pcb_data_t *Data, long int id, pcb_coord_t X1, pcb_coord_t Y1, pcb_coord_t X2, pcb_coord_t Y2, pcb_layergrp_id_t group1, pcb_layergrp_id_t group2, pcb_coord_t Thickness, pcb_flag_t Flags, pcb_any_obj_t *anchor1, pcb_any_obj_t *anchor2); pcb_bool pcb_rats_destroy(pcb_bool selected); +/* Look up the anchor object (object the rat is connected to) for end 0 or + end 1. If update is true, also update rat's field */ +pcb_any_obj_t *pcb_rat_anchor_guess(pcb_rat_t *rat, int end, pcb_bool update); + +/* Call pcb_rat_anchor_guess() on all rats of data, with update=true */ +void pcb_rat_all_anchor_guess(pcb_data_t *data); + + #define PCB_RAT_LOOP(top) do { \ pcb_rat_t *line; \ gdl_iterator_t __it__; \ Index: trunk/src/obj_rat_list.c =================================================================== --- trunk/src/obj_rat_list.c (revision 23610) +++ trunk/src/obj_rat_list.c (revision 23611) @@ -25,7 +25,9 @@ */ #include "config.h" + #include "layer_grp.h" +#include "obj_rat.h" #define TDL_DONT_UNDEF #include "obj_rat_list.h" Index: trunk/src_plugins/io_hyp/io_hyp.c =================================================================== --- trunk/src_plugins/io_hyp/io_hyp.c (revision 23610) +++ trunk/src_plugins/io_hyp/io_hyp.c (revision 23611) @@ -45,6 +45,7 @@ #include "parser.h" #include "board.h" #include "write.h" +#include "obj_rat.h" static const char *hyp_cookie = "hyp importer"; @@ -148,6 +149,7 @@ int res = hyp_parse(pcb->Data, Filename, 0); pcb_layer_auto_fixup(pcb); pcb_layer_colors_from_conf(pcb, 1); + pcb_rat_all_anchor_guess(pcb->Data); return res; } Index: trunk/src_plugins/io_hyp/parser.c =================================================================== --- trunk/src_plugins/io_hyp/parser.c (revision 23610) +++ trunk/src_plugins/io_hyp/parser.c (revision 23611) @@ -2295,7 +2295,7 @@ } pcb_rat_new(hyp_dest, -1, x2coord(h->x1), y2coord(h->y1), x2coord(h->x2), y2coord(h->y2), layer1_grp_id, layer2_grp_id, - xy2coord(h->width), pcb_no_flags()); + xy2coord(h->width), pcb_no_flags(), NULL, NULL); return 0; } Index: trunk/src_plugins/io_lihata/read.c =================================================================== --- trunk/src_plugins/io_lihata/read.c (revision 23610) +++ trunk/src_plugins/io_lihata/read.c (revision 23611) @@ -651,7 +651,7 @@ new_rat = pcb_rat_new(dt, rat.ID, rat.Point1.X, rat.Point1.Y, rat.Point2.X, rat.Point2.Y, rat.group1, rat.group2, - conf_core.appearance.rat_thickness, rat.Flags); + conf_core.appearance.rat_thickness, rat.Flags, NULL, NULL); parse_attributes(&new_rat->Attributes, lht_dom_hash_get(obj, "attributes")); @@ -2236,6 +2236,8 @@ vtp0_init(&post_thermal_old); vtp0_init(&post_thermal_heavy); + pcb_rat_all_anchor_guess(pcb->Data); + memset(&pcb->LayerGroups, 0, sizeof(pcb->LayerGroups)); if (parse_attributes(&pcb->Attributes, lht_dom_hash_get(nd, "attributes")) != 0) Index: trunk/src_plugins/io_pcb/file.c =================================================================== --- trunk/src_plugins/io_pcb/file.c (revision 23610) +++ trunk/src_plugins/io_pcb/file.c (revision 23611) @@ -1157,4 +1157,5 @@ pcb_subc_rebind(pcb, sc); pcb_layer_colors_from_conf(pcb, 1); + pcb_rat_all_anchor_guess(pcb->Data); } Index: trunk/src_plugins/io_pcb/parse_y.c =================================================================== --- trunk/src_plugins/io_pcb/parse_y.c (revision 23610) +++ trunk/src_plugins/io_pcb/parse_y.c (revision 23611) @@ -2234,7 +2234,7 @@ #line 576 "parse_y.y" /* yacc.c:1646 */ { pcb_rat_new(yyData, -1, NU ((yyvsp[-7].measure)), NU ((yyvsp[-6].measure)), NU ((yyvsp[-4].measure)), NU ((yyvsp[-3].measure)), (yyvsp[-5].integer), (yyvsp[-2].integer), - conf_core.appearance.rat_thickness, (yyvsp[-1].flagtype)); + conf_core.appearance.rat_thickness, (yyvsp[-1].flagtype), NULL, NULL); } #line 2240 "parse_y.c" /* yacc.c:1646 */ break; @@ -2243,7 +2243,7 @@ #line 581 "parse_y.y" /* yacc.c:1646 */ { pcb_rat_new(yyData, -1, OU ((yyvsp[-7].measure)), OU ((yyvsp[-6].measure)), OU ((yyvsp[-4].measure)), OU ((yyvsp[-3].measure)), (yyvsp[-5].integer), (yyvsp[-2].integer), - conf_core.appearance.rat_thickness, pcb_flag_old((yyvsp[-1].integer))); + conf_core.appearance.rat_thickness, pcb_flag_old((yyvsp[-1].integer)), NULL, NULL); } #line 2249 "parse_y.c" /* yacc.c:1646 */ break; Index: trunk/src_plugins/io_pcb/parse_y.y =================================================================== --- trunk/src_plugins/io_pcb/parse_y.y (revision 23610) +++ trunk/src_plugins/io_pcb/parse_y.y (revision 23611) @@ -575,12 +575,12 @@ : T_RAT '[' measure measure INTEGER measure measure INTEGER flags ']' { pcb_rat_new(yyData, -1, NU ($3), NU ($4), NU ($6), NU ($7), $5, $8, - conf_core.appearance.rat_thickness, $9); + conf_core.appearance.rat_thickness, $9, NULL, NULL); } | T_RAT '(' measure measure INTEGER measure measure INTEGER INTEGER ')' { pcb_rat_new(yyData, -1, OU ($3), OU ($4), OU ($6), OU ($7), $5, $8, - conf_core.appearance.rat_thickness, pcb_flag_old($9)); + conf_core.appearance.rat_thickness, pcb_flag_old($9), NULL, NULL); } ;