Index: trunk/src/select.c =================================================================== --- trunk/src/select.c (revision 31346) +++ trunk/src/select.c (revision 31347) @@ -216,7 +216,7 @@ * length of the list. Returns NULL on no match. */ TODO("cleanup: should be rewritten with generic ops and rtree") -static long int *ListBlock_(pcb_board_t *pcb, rnd_rnd_box_t *Box, rnd_bool Flag, int *len) +static long int *ListBlock_(pcb_board_t *pcb, rnd_rnd_box_t *Box, rnd_bool Flag, int *len, void *(cb)(void *ctx, pcb_any_obj_t *obj), void *ctx) { int changed = 0; int used = 0, alloced = 0; @@ -226,7 +226,7 @@ /*rnd_printf("box: %mm %mm - %mm %mm [ %d ] %d %d\n", Box->X1, Box->Y1, Box->X2, Box->Y2, PCB_IS_BOX_NEGATIVE(Box), rnd_conf.editor.view.flip_x, rnd_conf.editor.view.flip_y);*/ /* append an object to the return list OR set the flag if there's no list */ -#define append(undo_type, p1, obj) \ +#define append_list(undo_type, p1, obj) \ do { \ if (len == NULL) { \ pcb_undo_add_obj_to_flag(obj); \ @@ -243,6 +243,16 @@ changed = 1; \ } while(0) +#define append(undo_type, p1, obj) \ +do { \ + if (cb != NULL) { \ + cb(ctx, (pcb_any_obj_t *)obj); \ + used++; \ + } \ + else \ + append_list(undo_type, p1, obj); \ +} while(0) + if (PCB_IS_BOX_NEGATIVE(Box) && ((Box->X1 == Box->X2) || (Box->Y2 == Box->Y1))) { if (len != NULL) *len = 0; @@ -466,9 +476,16 @@ */ long int *pcb_list_block(pcb_board_t *pcb, rnd_rnd_box_t *Box, int *len) { - return ListBlock_(pcb, Box, 1, len); + return ListBlock_(pcb, Box, 1, len, NULL, NULL); } +int pcb_list_block_cb(pcb_board_t *pcb, rnd_rnd_box_t *Box, void *(cb)(void *ctx, pcb_any_obj_t *obj), void *ctx) +{ + int len = 0; + ListBlock_(pcb, Box, -1, &len, cb, ctx); + return len; +} + /* ---------------------------------------------------------------------- * selects/unselects all objects which were found during a connection scan * Flag determines if they are to be selected or unselected Index: trunk/src/select.h =================================================================== --- trunk/src/select.h (revision 31346) +++ trunk/src/select.h (revision 31347) @@ -38,8 +38,15 @@ rnd_bool pcb_select_object(pcb_board_t *pcb); rnd_bool pcb_select_block(pcb_board_t *pcb, rnd_rnd_box_t *Box, rnd_bool flag, rnd_bool vis_only, rnd_bool invert); + +/* List visible objects on screen within a box; return a list of IDs */ long int *pcb_list_block(pcb_board_t *pcb, rnd_rnd_box_t *Box, int *len); +/* List visible objects on screen within a box; return number of objects, call + a callback on each object found */ +int pcb_list_block_cb(pcb_board_t *pcb, rnd_rnd_box_t *Box, void *(cb)(void *ctx, pcb_any_obj_t *obj), void *ctx); + + rnd_bool pcb_select_connection(pcb_board_t *pcb, rnd_bool); #endif