Index: trunk/src/rats_patch.c =================================================================== --- trunk/src/rats_patch.c (revision 38274) +++ trunk/src/rats_patch.c (revision 38275) @@ -48,6 +48,8 @@ #include "conf_core.h" #include "netlist.h" #include "event.h" +#include "obj_subc_parent.h" +#include "data_it.h" static const char core_ratspatch_cookie[] = "core-rats-patch"; @@ -487,6 +489,51 @@ return cnt; } +/**** high level connections ****/ +long pcb_ratspatch_addconn_term(pcb_board_t *pcb, pcb_net_t *net, pcb_any_obj_t *obj) +{ + pcb_subc_t *subc = pcb_gobj_parent_subc(obj->parent_type, &obj->parent); + pcb_net_term_t *term; + char *termname; + + if (subc == NULL) + return 0; + + termname = rnd_strdup_printf("%s-%s", subc->refdes, obj->term); + term = pcb_net_find_by_obj(&pcb->netlist[PCB_NETLIST_EDITED], obj); + if (term != NULL) { + rnd_message(RND_MSG_ERROR, "Can not add %s to net %s because terminal is already part of a net\n", termname, net->name); + free(termname); + return 0; + } + + pcb_ratspatch_append_optimize(pcb, RATP_ADD_CONN, termname, net->name, NULL); + free(termname); + pcb_ratspatch_make_edited(pcb); + pcb_netlist_changed(0); + return 1; +} + +long pcb_ratspatch_addconn_selected(pcb_board_t *pcb, pcb_data_t *parent, pcb_net_t *net) +{ + long cnt = 0; + pcb_any_obj_t *obj; + pcb_data_it_t it; + + for(obj = pcb_data_first(&it, parent, PCB_OBJ_CLASS_REAL); obj != NULL; obj = pcb_data_next(&it)) { + if ((obj->term != NULL) && PCB_FLAG_TEST(PCB_FLAG_SELECTED, obj)) /* pick up terminals */ + cnt += pcb_ratspatch_addconn_term(pcb, net, obj); + + if (obj->type == PCB_OBJ_SUBC) { /* recurse to subc */ + pcb_subc_t *subc = (pcb_subc_t *)obj; + cnt += pcb_ratspatch_addconn_selected(pcb, subc->data, net); + } + } + + return cnt; +} + + /**** high level subc ****/ Index: trunk/src/rats_patch.h =================================================================== --- trunk/src/rats_patch.h (revision 38274) +++ trunk/src/rats_patch.h (revision 38275) @@ -83,6 +83,12 @@ /* Unlink n from the list; if do_free is non-zero, also free fields and n */ void rats_patch_remove(pcb_board_t *pcb, pcb_ratspatch_line_t *n, int do_free); +/**** high level calls for connection add/remove ****/ + +long pcb_ratspatch_addconn_term(pcb_board_t *pcb, pcb_net_t *net, pcb_any_obj_t *obj); +long pcb_ratspatch_addconn_selected(pcb_board_t *pcb, pcb_data_t *parent, pcb_net_t *net); + + /**** high level calls for subc add/remove ****/ /* Add a subc to the netlist patch of pcb if subc is not already on it. Index: trunk/src_plugins/dialogs/dlg_netlist.c =================================================================== --- trunk/src_plugins/dialogs/dlg_netlist.c (revision 38274) +++ trunk/src_plugins/dialogs/dlg_netlist.c (revision 38275) @@ -26,7 +26,6 @@ #include "event.h" #include "netlist.h" -#include "data_it.h" #include #include @@ -264,49 +263,6 @@ pcb_netlist_changed(0); } -long pcb_ratspatch_addconn_term(pcb_board_t *pcb, pcb_net_t *net, pcb_any_obj_t *obj) -{ - pcb_subc_t *subc = pcb_gobj_parent_subc(obj->parent_type, &obj->parent); - pcb_net_term_t *term; - char *termname; - - if (subc == NULL) - return 0; - - termname = rnd_strdup_printf("%s-%s", subc->refdes, obj->term); - term = pcb_net_find_by_obj(&pcb->netlist[PCB_NETLIST_EDITED], obj); - if (term != NULL) { - rnd_message(RND_MSG_ERROR, "Can not add %s to net %s because terminal is already part of a net\n", termname, net->name); - free(termname); - return 0; - } - - pcb_ratspatch_append_optimize(pcb, RATP_ADD_CONN, termname, net->name, NULL); - free(termname); - pcb_ratspatch_make_edited(pcb); - pcb_netlist_changed(0); - return 1; -} - -long pcb_ratspatch_addconn_selected(pcb_board_t *pcb, pcb_data_t *parent, pcb_net_t *net) -{ - long cnt = 0; - pcb_any_obj_t *obj; - pcb_data_it_t it; - - for(obj = pcb_data_first(&it, parent, PCB_OBJ_CLASS_REAL); obj != NULL; obj = pcb_data_next(&it)) { - if ((obj->term != NULL) && PCB_FLAG_TEST(PCB_FLAG_SELECTED, obj)) /* pick up terminals */ - cnt += pcb_ratspatch_addconn_term(pcb, net, obj); - - if (obj->type == PCB_OBJ_SUBC) { /* recurse to subc */ - pcb_subc_t *subc = (pcb_subc_t *)obj; - cnt += pcb_ratspatch_addconn_selected(pcb, subc->data, net); - } - } - - return cnt; -} - static void addconn_button_cb(void *hid_ctx, void *caller_data, rnd_hid_attribute_t *attr) { netlist_ctx_t *ctx = caller_data;