Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10712) +++ trunk/src/plugins/io_easyeda/read.c (revision 10713) @@ -125,6 +125,7 @@ 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 */ + const char *symtab_key;/* also add first PART of a symbol into the symtab with this key (ver 1.0 files tend to reference symbols via a Symbol attr using the hash-like name) */ 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_draw.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro_draw.c (revision 10712) +++ trunk/src/plugins/io_easyeda/read_hi_pro_draw.c (revision 10713) @@ -131,6 +131,11 @@ csch_cobj_attrib_set(ctx->sheet, *parent, CSCH_ATP_HARDWIRED, "role", "symbol", src); htsp_insert(ctx->pro_symtab, rnd_strdup(name), *parent); + if (ctx->symtab_key != NULL) { + /* also save a hash-like name link, 1.0 sheets sometime refer using that */ + htsp_insert(ctx->pro_symtab, rnd_strdup(ctx->symtab_key), *parent); + ctx->symtab_key = NULL; + } } else if (ctx->pro_want_slot == -1) { double x1, x2/*, y1, y2*/; @@ -680,9 +685,39 @@ return 0; } +/* Read ATTR subtrees following the current COMPONENT (obj) to find the + first one that has key Symbol; the value is the hash-like name of + the symbol to use. This is useful when the COMPONENT line doesn't + have a symbol name */ +static const char *easypro_find_synmanme(read_ctx_t *ctx, gdom_node_t *obj, long objidx) +{ + gdom_node_t *parent = obj->parent, *attr, *key; + long n; + + assert(parent->type == GDOM_ARRAY); + + for(n = objidx+1; n < parent->value.array.used; n++) { + attr = parent->value.array.child[n]; + if ((attr->type != GDOM_ARRAY) || (attr->value.array.used < 1)) + return NULL; + + key = attr->value.array.child[0]; + if ((key->type == GDOM_STRING) && (strcmp(key->value.str, "COMPONENT") == 0)) + return NULL; + + if ((key->type == GDOM_STRING) && (strcmp(key->value.str, "ATTR") == 0)) { + if ((attr->value.array.used >= 5) && (strcmp(attr->value.array.child[3]->value.str, "Symbol") == 0)) + return attr->value.array.child[4]->value.str; + } + } + + return NULL; +} + + /* "COMPONENT","e152","LM358.1",190,360,0, 0, {},0 kw id symname x y rot mirx ? ? */ -static int easypro_parse_component(read_ctx_t *ctx, gdom_node_t *obj, csch_cgrp_t *parent) +static int easypro_parse_component(read_ctx_t *ctx, gdom_node_t *obj, long objidx, csch_cgrp_t *parent) { const char *symname; double x, y, rot, mirx; @@ -702,6 +737,16 @@ GET_ARG_DBL(rot, obj, 5, "easypro_parse_component: rotation", return -1); GET_ARG_DBL(mirx, obj, 6, "easypro_parse_component: mirror-x", return -1); + /* if the COMPONENT line doesn't specify a symbol name, pick it out from + the hash-like name from Symbol ATTR following the COMPONENT */ + if ((symname == NULL) || (*symname == '\0')) { + symname = easypro_find_synmanme(ctx, obj, objidx); + if (symname == NULL) { + error_at(ctx, obj, ("easypro_parse_component: failed to find symbol name from ATTR\n")); + return -1; + } + } + src = htsp_get(ctx->pro_symtab, symname); if (src == NULL) { error_at(ctx, obj, ("easypro_parse_component: failed to find symbol '%s' in symtab - not in the project file?\n", symname)); @@ -753,7 +798,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, long objidx, csch_cgrp_t **parent) { char *cmds; int cmdi; @@ -776,7 +821,7 @@ 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_COMPONENT: return easypro_parse_component(ctx, obj, objidx, *parent); case easy_WIRE: return easypro_parse_wire(ctx, obj, *parent); case easy_FONTSTYLE: return 0; /* ignore: sch-rnd uses pens */ Index: trunk/src/plugins/io_easyeda/read_hi_pro_glue.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro_glue.c (revision 10712) +++ trunk/src/plugins/io_easyeda/read_hi_pro_glue.c (revision 10713) @@ -73,7 +73,7 @@ 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], &parent); + rv = easypro_parse_any_obj(&ctx, ctx.root->value.array.child[n], n, &parent); } if (rv == 0) { @@ -119,7 +119,7 @@ /* 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], n, &resgrp); if (rv == 0) { csch_cgrp_update(ctx->sheet, resgrp, 1); @@ -393,6 +393,7 @@ sname = rnd_strdup(jctx.name); /* rnd_trace(" sname: %s\n", jctx.name);*/ } + case NJSON_SEM_EV_ARRAY_BEGIN: level++; /* rnd_trace(" [%d %d] %s\n", level, tmain, jctx.name);*/ @@ -415,7 +416,7 @@ if ((level == 3) && (tmain == M_SYM)) { /* finished reading a symbol block */ char *name, *path; /* rnd_trace("!sym flush! sname=%s title=%s\n", sname, user_name);*/ - name = user_name; + name = rnd_strdup(sname); /* user name should be the hash-like name, in some cases the sheet will reference using that */ path = rnd_concat(bnd->dir, "/SYMBOL/", sname, ".esym", NULL); vts0_append(&bnd->syms, name); @@ -462,18 +463,6 @@ } break; case M_SYM: - if (level != 3) break; - /* reading items of a symbol block */ -/* rnd_trace(" [%d] sym atom: %s\n", level, jctx.name);*/ - if (strcmp(jctx.name, "title") == 0) { - if (jctx.type != NJSON_SEM_TYPE_STRING) { - rnd_message(RND_MSG_ERROR, "easypro sheet init: project.json parse error: sym title must be a string at %ld:%ld\n", jctx.njs.lineno, jctx.njs.col); - goto error; - } - if (user_name != NULL) free(user_name); - user_name = rnd_strdup(jctx.value.string); - } - break; } break; @@ -518,7 +507,7 @@ alien_setup(&symctx); for(n = 0; n < bnd->syms.used; n+=2) { -/* const char *key = bnd->syms.array[n];*/ + const char *key = bnd->syms.array[n]; const char *path = bnd->syms.array[n+1]; csch_cgrp_t *sym; @@ -529,6 +518,7 @@ } symctx.fn = path; + symctx.symtab_key = key; sym = easypro_load_sym(&symctx, NULL); fclose(symctx.f);