Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10680) +++ trunk/src/plugins/io_easyeda/read.c (revision 10681) @@ -122,6 +122,7 @@ int pro_want_slot; /* which slot to load; -1 means all */ int pro_slot; /* current slot ID, numbered from 1 */ int pro_stop; /* stop reading the root array */ + htsp_t *pro_symtab; /* if not NULL, add each sym PART as a separate group */ int pass; /* do multiple passes because some objects can be created only when others are already created */ } read_ctx_t; Index: trunk/src/plugins/io_easyeda/read_hi_pro.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10680) +++ trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10681) @@ -113,14 +113,26 @@ /*** parse obj subtrees (lines in the file) ***/ /* Announces a slot (even for single-slot parts); slots are full copies */ -static int easypro_parse_part(read_ctx_t *ctx, gdom_node_t *obj, csch_cgrp_t *parent) +static int easypro_parse_part(read_ctx_t *ctx, gdom_node_t *obj, csch_cgrp_t **parent) { gdom_node_t *bbox, *coords; REQ_ARGC_GTE(obj, 3, "easypro_parse_part", return -1); - GET_ARG_HASH(bbox, obj, 2, "easypro_verify_header: HEAD", return -1); + GET_ARG_HASH(bbox, obj, 2, "easypro_parse_part: bbox", return -1); ctx->pro_slot++; - if (ctx->pro_want_slot == -1) { + if (ctx->pro_symtab != NULL) { /* create a new symbol group for the new part */ + csch_source_arg_t *src; + const char *name; + + GET_ARG_STR(name, obj, 1, "easypro_parse_part: name", return -1); + + *parent = csch_cgrp_alloc(ctx->sheet, &ctx->sheet->direct, csch_oid_new(ctx->sheet, &ctx->sheet->direct)); + src = csch_attrib_src_c(ctx->fn, 0, 0, NULL); /* whole-file context, no need to set location */ + csch_cobj_attrib_set(ctx->sheet, *parent, CSCH_ATP_HARDWIRED, "role", "symbol", src); + + htsp_insert(ctx->pro_symtab, rnd_strdup(name), *parent); + } + else if (ctx->pro_want_slot == -1) { double x1, y1, x2, y2; coords = gdom_hash_get(bbox, easy_BBOX); @@ -142,8 +154,7 @@ else if (ctx->pro_slot > ctx->pro_want_slot) ctx->pro_stop = 1; /* don't read any more slots */ - TODO("maybe also save name"); - ctx->pro_last = parent; + ctx->pro_last = *parent; return 0; } @@ -685,7 +696,7 @@ } /* object dispatcher */ -static int easypro_parse_any_obj(read_ctx_t *ctx, gdom_node_t *obj, csch_cgrp_t *parent) +static int easypro_parse_any_obj(read_ctx_t *ctx, gdom_node_t *obj, csch_cgrp_t **parent) { char *cmds; int cmdi; @@ -696,20 +707,20 @@ switch(cmdi) { case easy_PART: return easypro_parse_part(ctx, obj, parent); - case easy_PIN: return easypro_parse_pin(ctx, obj, parent); - case easy_ATTR: return easypro_parse_attr(ctx, obj, parent); - case easy_POLY: return easypro_parse_poly(ctx, obj, parent); - case easy_ARC: return easypro_parse_arc(ctx, obj, parent); - case easy_CIRCLE: return easypro_parse_circle(ctx, obj, parent); - case easy_ELLIPSE: return easypro_parse_ellipse(ctx, obj, parent); - case easy_RECT: return easypro_parse_rect(ctx, obj, parent); - case easy_BEZIER: return easypro_parse_bezier(ctx, obj, parent); - case easy_TEXT: return easypro_parse_text(ctx, obj, parent); - case easy_GROUP: return easypro_parse_group(ctx, obj, parent); - case easy_OBJ: return easypro_parse_obj(ctx, obj, parent); - case easy_LINESTYLE: return easypro_parse_linestyle(ctx, obj, parent); - case easy_COMPONENT: return easypro_parse_component(ctx, obj, parent); - case easy_WIRE: return easypro_parse_wire(ctx, obj, parent); + case easy_PIN: return easypro_parse_pin(ctx, obj, *parent); + case easy_ATTR: return easypro_parse_attr(ctx, obj, *parent); + case easy_POLY: return easypro_parse_poly(ctx, obj, *parent); + case easy_ARC: return easypro_parse_arc(ctx, obj, *parent); + case easy_CIRCLE: return easypro_parse_circle(ctx, obj, *parent); + case easy_ELLIPSE: return easypro_parse_ellipse(ctx, obj, *parent); + case easy_RECT: return easypro_parse_rect(ctx, obj, *parent); + case easy_BEZIER: return easypro_parse_bezier(ctx, obj, *parent); + case easy_TEXT: return easypro_parse_text(ctx, obj, *parent); + case easy_GROUP: return easypro_parse_group(ctx, obj, *parent); + case easy_OBJ: return easypro_parse_obj(ctx, obj, *parent); + case easy_LINESTYLE: return easypro_parse_linestyle(ctx, obj, *parent); + case easy_COMPONENT: return easypro_parse_component(ctx, obj, *parent); + case easy_WIRE: return easypro_parse_wire(ctx, obj, *parent); case easy_FONTSTYLE: return 0; /* ignore: sch-rnd uses pens */ @@ -819,9 +830,11 @@ } /* parse the data section of the tree */ - if (rv == 0) + if (rv == 0) { + csch_cgrp_t *parent = &sheet->direct; for(n = starti; !ctx.pro_stop && (rv == 0) && (n < ctx.root->value.array.used); n++) - rv = easypro_parse_any_obj(&ctx, ctx.root->value.array.child[n], &sheet->direct); + rv = easypro_parse_any_obj(&ctx, ctx.root->value.array.child[n], &parent); + } if (rv == 0) { csch_cgrp_update(sheet, &sheet->direct, 1); @@ -851,20 +864,22 @@ if (starti < 0) return NULL; - /* create the symbol group */ - if (resgrp == NULL) { - resgrp = csch_cgrp_alloc(ctx->sheet, &ctx->sheet->direct, csch_oid_new(ctx->sheet, &ctx->sheet->direct)); - alloced = 1; + if (ctx->pro_symtab == NULL) { + /* create the symbol group (if not creating one per PART for a symtab) */ + if (resgrp == NULL) { + resgrp = csch_cgrp_alloc(ctx->sheet, &ctx->sheet->direct, csch_oid_new(ctx->sheet, &ctx->sheet->direct)); + alloced = 1; + } + + src = csch_attrib_src_c(ctx->fn, 0, 0, NULL); /* whole-file context, no need to set location */ + csch_cobj_attrib_set(ctx->sheet, resgrp, CSCH_ATP_HARDWIRED, "role", "symbol", src); } - src = csch_attrib_src_c(ctx->fn, 0, 0, NULL); /* whole-file context, no need to set location */ - csch_cobj_attrib_set(ctx->sheet, resgrp, CSCH_ATP_HARDWIRED, "role", "symbol", src); - easypro_init_ctx(ctx); /* parse the data section of the tree */ for(n = starti; !ctx->pro_stop && (rv == 0) && (n < ctx->root->value.array.used); n++) - rv = easypro_parse_any_obj(ctx, ctx->root->value.array.child[n], resgrp); + rv = easypro_parse_any_obj(ctx, ctx->root->value.array.child[n], &resgrp); if (rv == 0) { csch_cgrp_update(ctx->sheet, resgrp, 1); @@ -1017,6 +1032,7 @@ /* bundled seet load */ unsigned sheet_loader_inited:1; unsigned symsheet_inited:1; + unsigned symtab_inited:1; vts0_t sheets; /* list of name,filename pairs of all sheets */ vts0_t syms; /* list of name,filename pairs of all syms */ int sheet_idx; /* within ->sheets */ @@ -1256,6 +1272,10 @@ bnd->symsheet_inited = 1; symctx.sheet = &bnd->symsheet; + symctx.pro_symtab = &bnd->symtab; + htsp_init(&bnd->symtab, strhash, strkeyeq); + bnd->symtab_inited = 1; + alien_setup(&symctx); TODO("load all symbols into bnd->symtab"); @@ -1405,6 +1425,13 @@ if (bnd->symsheet_inited) csch_sheet_uninit(&bnd->symsheet); + if (bnd->symtab_inited) { + htsp_entry_t *e; + for(e = htsp_first(&bnd->symtab); e != NULL; e = htsp_next(&bnd->symtab, e)) + free(e->key); + htsp_uninit(&bnd->symtab); + } + free(bnd); }