added bus (cached from attr) member in Polygon struct for efficiency

This commit is contained in:
stefan schippers 2025-11-25 15:25:42 +01:00
parent 179a1502ae
commit d8fb5b1480
8 changed files with 34 additions and 29 deletions

View File

@ -218,8 +218,10 @@ void trim_wires(void)
}
xctx->wire[xctx->wires].prop_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[j].prop_ptr);
xctx->wire[xctx->wires].bus =
get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
/* xctx->wire[xctx->wires].bus =
* get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
*/
xctx->wire[xctx->wires].bus = xctx->wire[j].bus;
xctx->wire[xctx->wires].node=NULL;
my_strdup(_ALLOC_ID_, &xctx->wire[xctx->wires].node, xctx->wire[j].node);
@ -498,8 +500,10 @@ void break_wires_at_point(double x0, double y0, int align)
xctx->wire[xctx->wires].sel=0;
xctx->wire[xctx->wires].prop_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr);
xctx->wire[xctx->wires].bus =
get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
/* xctx->wire[xctx->wires].bus =
* get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
*/
xctx->wire[xctx->wires].bus = xctx->wire[i].bus;
xctx->wire[xctx->wires].node=NULL;
hash_wire(XINSERT, xctx->wires, 0); /* insertion happens at beginning of list */
dbg(1, "break_wires_at_pins(): hashing new wire %d: %g %g %g %g\n",
@ -573,8 +577,10 @@ void break_wires_at_pins(int remove)
xctx->wire[xctx->wires].sel=xctx->wire[i].sel;
xctx->wire[xctx->wires].prop_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr);
xctx->wire[xctx->wires].bus =
get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus", 0));
/* xctx->wire[xctx->wires].bus =
* get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus", 0));
*/
xctx->wire[xctx->wires].bus = xctx->wire[i].bus;
xctx->wire[xctx->wires].node=NULL;
hash_wire(XINSERT, xctx->wires, 0); /* insertion happens at beginning of list */
dbg(1, "break_wires_at_pins(): hashing new wire %d: %g %g %g %g\n",
@ -667,8 +673,10 @@ void break_wires_at_pins(int remove)
set_first_sel(WIRE, xctx->wires, 0);
xctx->wire[xctx->wires].prop_ptr=NULL;
my_strdup(_ALLOC_ID_, &xctx->wire[xctx->wires].prop_ptr, xctx->wire[i].prop_ptr);
xctx->wire[xctx->wires].bus =
get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
/* xctx->wire[xctx->wires].bus =
* get_attr_val(get_tok_value(xctx->wire[xctx->wires].prop_ptr,"bus",0));
*/
xctx->wire[xctx->wires].bus = xctx->wire[i].bus;
xctx->wire[xctx->wires].node=NULL;
hash_wire(XINSERT, xctx->wires, 0); /* insertion happens at beginning of list */
xctx->need_reb_sel_arr=1;

View File

@ -744,7 +744,8 @@ void draw_symbol(int what,int c, int n,int layer,short tmp_flip, short rot,
int bezier;
int bus;
polygon = &(symptr->poly[layer])[j];
bus = get_attr_val(get_tok_value(polygon->prop_ptr, "bus", 0)) ? THICK : NOW;
/* bus = get_attr_val(get_tok_value(polygon->prop_ptr, "bus", 0)) ? THICK : NOW; */
bus = polygon->bus ? THICK : NOW;
bezier = !strboolcmp(get_tok_value(polygon->prop_ptr, "bezier", 0), "true");
dash = (disabled == 1) ? 3 : polygon->dash;
x = my_malloc(_ALLOC_ID_, sizeof(double) * polygon->points);
@ -5180,7 +5181,8 @@ void draw(void)
if(draw_layer && xctx->enable_layer[c]) for(i=0;i<xctx->polygons[c]; ++i) {
int bezier;
xPoly *p = &xctx->poly[c][i];
int bus = get_attr_val(get_tok_value(p->prop_ptr, "bus", 0)) ? THICK : NOW;
/* int bus = get_attr_val(get_tok_value(p->prop_ptr, "bus", 0)) ? THICK : NOW; */
int bus = p->bus ? THICK : NOW;
bezier = 2 + !strboolcmp(get_tok_value(p->prop_ptr, "bezier", 0), "true");
drawpolygon(cc, bus, p->x, p->y, p->points, p->fill, p->dash, bezier);
}

View File

@ -1186,14 +1186,13 @@ static int edit_wire_property(void)
} else {
my_strdup(_ALLOC_ID_, &xctx->wire[k].prop_ptr,(char *) tclgetvar("tctx::retval"));
}
bus = get_attr_val(get_tok_value(xctx->wire[k].prop_ptr,"bus",0));
xctx->wire[k].bus = bus = get_attr_val(get_tok_value(xctx->wire[k].prop_ptr,"bus",0));
if(bus) {
double ov, y1, y2;
ov = INT_BUS_WIDTH(xctx->lw) > xctx->cadhalfdotsize ? INT_BUS_WIDTH(xctx->lw) : CADHALFDOTSIZE;
if(xctx->wire[k].y1 < xctx->wire[k].y2) { y1 = xctx->wire[k].y1-ov; y2 = xctx->wire[k].y2+ov; }
else { y1 = xctx->wire[k].y1+ov; y2 = xctx->wire[k].y2-ov; }
bbox(ADD, xctx->wire[k].x1-ov, y1 , xctx->wire[k].x2+ov , y2 );
xctx->wire[k].bus=1;
} else {
if(oldbus){
double ov, y1, y2;
@ -1201,7 +1200,6 @@ static int edit_wire_property(void)
if(xctx->wire[k].y1 < xctx->wire[k].y2) { y1 = xctx->wire[k].y1-ov; y2 = xctx->wire[k].y2+ov; }
else { y1 = xctx->wire[k].y1+ov; y2 = xctx->wire[k].y2-ov; }
bbox(ADD, xctx->wire[k].x1-ov, y1 , xctx->wire[k].x2+ov , y2 );
xctx->wire[k].bus=0;
}
}
}
@ -1291,7 +1289,7 @@ static int edit_polygon_property(void)
int oldbezier, bezier;
int k;
double x1=0., y1=0., x2=0., y2=0.;
int c, i, ii, old_dash, old_bus, bus;
int c, i, ii, old_dash, oldbus, bus;
int drw = 0;
char *oldprop = NULL;
const char *dash;
@ -1318,7 +1316,8 @@ static int edit_polygon_property(void)
c = xctx->sel_array[ii].col;
oldbezier = !strboolcmp(get_tok_value(xctx->poly[c][i].prop_ptr,"bezier",0),"true") ;
old_bus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr,"bus",0));
/* oldbus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr,"bus",0)); */
oldbus = xctx->poly[c][i].bus;
if(oldprop && preserve == 1) {
set_different_token(&xctx->poly[c][i].prop_ptr, (char *) tclgetvar("tctx::retval"), oldprop);
} else {
@ -1327,7 +1326,7 @@ static int edit_polygon_property(void)
old_fill = xctx->poly[c][i].fill;
old_dash = xctx->poly[c][i].dash;
bezier = !strboolcmp(get_tok_value(xctx->poly[c][i].prop_ptr,"bezier",0),"true") ;
bus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr,"bus",0));
xctx->poly[c][i].bus = bus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr,"bus",0));
fill_ptr = get_tok_value(xctx->poly[c][i].prop_ptr,"fill",0);
if( !strcmp(fill_ptr,"full") )
@ -1343,7 +1342,7 @@ static int edit_polygon_property(void)
} else
xctx->poly[c][i].dash = 0;
if(old_fill != xctx->poly[c][i].fill || old_dash != xctx->poly[c][i].dash ||
oldbezier != bezier || old_bus != bus) {
oldbezier != bezier || oldbus != bus) {
if(!drw) {
bbox(START,0.0,0.0,0.0,0.0);
drw = 1;

View File

@ -231,7 +231,7 @@ static void merge_polygon(FILE *fd)
} else {
ptr[i].dash = 0;
}
ptr[i].bus = get_attr_val(get_tok_value(ptr[i].prop_ptr, "bus", 0));
select_polygon(c,i, SELECTED, 1, 1);
xctx->polygons[c]++;
}

View File

@ -1033,10 +1033,8 @@ static void ps_draw_symbol(int c, int n,int layer, int what, short tmp_flip, sho
{
int dash;
int bezier;
int bus;
polygon = &(symptr->poly[layer])[j];
bezier = !strboolcmp(get_tok_value(polygon->prop_ptr, "bezier", 0), "true");
bus = get_attr_val(get_tok_value(polygon->prop_ptr, "bus", 0));
dash = (disabled == 1) ? 3 : polygon->dash;
{ /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */
int k;
@ -1047,7 +1045,7 @@ static void ps_draw_symbol(int c, int n,int layer, int what, short tmp_flip, sho
x[k]+= x0;
y[k] += y0;
}
ps_drawpolygon(c, NOW, x, y, polygon->points, polygon->fill, dash, bezier, bus);
ps_drawpolygon(c, NOW, x, y, polygon->points, polygon->fill, dash, bezier, polygon->bus);
my_free(_ALLOC_ID_, &x);
my_free(_ALLOC_ID_, &y);
}
@ -1481,9 +1479,8 @@ void create_ps(char **psfile, int what, int fullzoom, int eps)
}
for(i=0;i<xctx->polygons[c]; ++i) {
int bezier = !strboolcmp(get_tok_value(xctx->poly[c][i].prop_ptr, "bezier", 0), "true");
int bus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr, "bus", 0));
ps_drawpolygon(c, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points,
xctx->poly[c][i].fill, xctx->poly[c][i].dash, bezier, bus);
xctx->poly[c][i].fill, xctx->poly[c][i].dash, bezier, xctx->poly[c][i].bus);
}
dbg(1, "create_ps(): starting drawing symbols on layer %d\n", c);
} /* for(c=0;c<cadlayers; ++c) */

View File

@ -2924,6 +2924,7 @@ static void load_polygon(FILE *fd)
} else {
ptr[i].dash = 0;
}
ptr[i].bus = get_attr_val(get_tok_value(ptr[i].prop_ptr, "bus", 0));
xctx->polygons[c]++;
}
@ -4520,7 +4521,7 @@ int load_sym_def(const char *name, FILE *embed_fd)
pp[c][i].dash = 0;
pp[c][i].sel = 0;
pp[c][i].bus = get_attr_val(get_tok_value(pp[c][i].prop_ptr,"bus", 0));
dbg(2, "l_s_d(): loaded polygon: ptr=%lx\n", (unsigned long)pp[c]);
lastp[c]++;
break;

View File

@ -714,9 +714,7 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot,
for(j=0;j< symptr->polygons[layer]; ++j) {
int dash;
int bezier;
int bus;
polygon =&(symptr->poly[layer])[j];
bus = get_attr_val(get_tok_value(polygon->prop_ptr, "bus", 0));
bezier = !strboolcmp(get_tok_value(polygon->prop_ptr, "bezier", 0), "true");
dash = (disabled == 1) ? 3 : polygon->dash;
{ /* scope block so we declare some auxiliary arrays for coord transforms. 20171115 */
@ -728,7 +726,7 @@ static void svg_draw_symbol(int c, int n,int layer,short tmp_flip, short rot,
x[k]+= x0;
y[k] += y0;
}
svg_drawpolygon(c, NOW, x, y, polygon->points, polygon->fill, dash, bezier, bus);
svg_drawpolygon(c, NOW, x, y, polygon->points, polygon->fill, dash, bezier, polygon->bus);
my_free(_ALLOC_ID_, &x);
my_free(_ALLOC_ID_, &y);
}
@ -1076,9 +1074,8 @@ void svg_draw(void)
}
for(i=0;i<xctx->polygons[c]; ++i) {
int bezier = !strboolcmp(get_tok_value(xctx->poly[c][i].prop_ptr, "bezier", 0), "true");
int bus = get_attr_val(get_tok_value(xctx->poly[c][i].prop_ptr, "bus", 0));
svg_drawpolygon(c, NOW, xctx->poly[c][i].x, xctx->poly[c][i].y, xctx->poly[c][i].points,
xctx->poly[c][i].fill, xctx->poly[c][i].dash, bezier, bus);
xctx->poly[c][i].fill, xctx->poly[c][i].dash, bezier, xctx->poly[c][i].bus);
}
for(i=0;i<xctx->instances; ++i) {
svg_draw_symbol(c,i,c,0,0,0.0,0.0);

View File

@ -519,6 +519,7 @@ typedef struct
char *prop_ptr;
short fill;
short dash;
int bus;
} xPoly;
typedef struct