Index: trunk/src/conf_core.h =================================================================== --- trunk/src/conf_core.h (revision 32457) +++ trunk/src/conf_core.h (revision 32458) @@ -190,6 +190,7 @@ RND_CFT_BOOLEAN subc_layer_per_side; /* hide top or bottom placed subcircuit annotations if the view is showing the other side */ RND_CFT_BOOLEAN invis_other_groups; /* render non-current group layers with the inivisble color */ RND_CFT_BOOLEAN black_current_group; /* render all layers of the current group black, for maximum contrast */ + RND_CFT_BOOLEAN smart_labels; /* attempt to place terminal labels in a way they don't overlap (costs extra CPU cycles, may slow down on-screen rendering) */ struct { /* color */ RND_CFT_COLOR crosshair; /* obsolete - DO NOT USE - kept for compatibility (use appearance/color/cross instead) */ Index: trunk/src/draw.c =================================================================== --- trunk/src/draw.c (revision 32457) +++ trunk/src/draw.c (revision 32458) @@ -624,6 +624,8 @@ } } +#include "draw_label_smart.c" + /* --------------------------------------------------------------------------- * Draws padstacks' names - Always draws for non-gui HIDs, * otherwise drawing depends on PCB->pstk_on @@ -635,6 +637,7 @@ for(n = 0; n < delayed_labels.used; n++) pcb_draw_obj_label(info, group, delayed_labels.array[n]); } + pcb_label_smart_flush(info); delayed_labels.used = 0; } @@ -1268,20 +1271,27 @@ void pcb_label_draw(pcb_draw_info_t *info, rnd_coord_t x, rnd_coord_t y, double scale, rnd_bool vert, rnd_bool centered, const char *label) { int mirror, direction; + PCB_TERM_LABEL_SETUP((const unsigned char *)label); mirror = (flip_x ^ flip_y) ? PCB_TXT_MIRROR_Y : 0; direction = (vert ? 1 : 0); - rnd_render->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.pin_name); + if (!conf_core.appearance.smart_labels) { - if (rnd_render->gui) - pcb_draw_force_termlab++; - pcb_text_draw_string(info, font, (unsigned const char *)label, x, y, scale/100, scale/100, direction*90.0, mirror, 1, 0, 0, 0, 0, PCB_TXT_TINY_HIDE); - if (rnd_render->gui) - pcb_draw_force_termlab--; + rnd_render->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.pin_name); + + if (rnd_render->gui) + pcb_draw_force_termlab++; + pcb_text_draw_string(info, font, (unsigned const char *)label, x, y, scale/100, scale/100, direction*90.0, mirror, 1, 0, 0, 0, 0, PCB_TXT_TINY_HIDE); + if (rnd_render->gui) + pcb_draw_force_termlab--; + } + else + pcb_label_smart_add(info, x, y, scale/100.0, direction*90.0, mirror, w, h, label); } + void pcb_label_invalidate(rnd_coord_t x, rnd_coord_t y, double scale, rnd_bool vert, rnd_bool centered, const char *label) { rnd_coord_t ox = x, oy = y, margin = 0; Index: trunk/src/draw_label_smart.c =================================================================== --- trunk/src/draw_label_smart.c (nonexistent) +++ trunk/src/draw_label_smart.c (revision 32458) @@ -0,0 +1,61 @@ +typedef struct pcb_smart_label_s pcb_smart_label_t; + +struct pcb_smart_label_s { + rnd_box_t bbox; + rnd_coord_t x; + rnd_coord_t y; + double scale; + double rot; + rnd_bool mirror; + rnd_coord_t w; + rnd_coord_t h; + pcb_smart_label_t *next; + char label[1]; /* dynamic length array */ +}; + +static pcb_smart_label_t *smart_labels = NULL; + +RND_INLINE void pcb_label_smart_add(pcb_draw_info_t *info, rnd_coord_t x, rnd_coord_t y, double scale, double rot, rnd_bool mirror, rnd_coord_t w, rnd_coord_t h, const char *label) +{ + int len = strlen(label); + pcb_smart_label_t *l = malloc(sizeof(pcb_smart_label_t) + len + 1); + + l->x = x; l->y = y; + l->scale = scale; + l->rot = rot; + l->mirror = mirror; + l->w = w; l->h = h; + memcpy(l->label, label, len+1); + + l->next = smart_labels; + smart_labels = l; +} + +/*RND_INLINE void lsm_place() +{ + +}*/ + + +RND_INLINE void pcb_label_smart_flush(pcb_draw_info_t *info) +{ + pcb_smart_label_t *l, *next; + pcb_font_t *font; + + if (smart_labels == NULL) return; + + font = pcb_font(PCB, 0, 0); + rnd_render->set_color(pcb_draw_out.fgGC, &conf_core.appearance.color.pin_name); + if (rnd_render->gui) + pcb_draw_force_termlab++; + + for(l = smart_labels; l != NULL; l = next) { + next = l->next; + pcb_text_draw_string(info, font, (unsigned const char *)l->label, l->x, l->y, l->scale, l->scale, l->rot, l->mirror, 1, 0, 0, 0, 0, PCB_TXT_TINY_HIDE); + free(l); + } + smart_labels = NULL; + + if (rnd_render->gui) + pcb_draw_force_termlab--; +} Index: trunk/src/obj_subc.h =================================================================== --- trunk/src/obj_subc.h (revision 32457) +++ trunk/src/obj_subc.h (revision 32458) @@ -127,7 +127,7 @@ /* calculate geometrical properties using the aux layer; return 0 on success */ int pcb_subc_get_origin(pcb_subc_t *sc, rnd_coord_t *x, rnd_coord_t *y); -int pcb_subc_get_rotation(pcb_subc_t *sc, double *rot); +int pcb_subc_get_rotation(pcb_subc_t *sc, double *rot); /* in deg */ int pcb_subc_get_side(pcb_subc_t *sc, int *on_bottom); /* get all the above transformatoins at once. If neg is 0, these are the