Index: trunk/src/plugins/io_easyeda/easyeda.sphash =================================================================== --- trunk/src/plugins/io_easyeda/easyeda.sphash (revision 10674) +++ trunk/src/plugins/io_easyeda/easyeda.sphash (revision 10675) @@ -6,6 +6,7 @@ BEZIER CIRCLE Contributor +COMPONENT DOCTYPE ELLIPSE FONTSTYLE @@ -22,6 +23,7 @@ Supplier Supplier Part TEXT +WIRE arc arrowhead attributes Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10674) +++ trunk/src/plugins/io_easyeda/read.c (revision 10675) @@ -59,6 +59,7 @@ #include #include #include +#include #include #include Index: trunk/src/plugins/io_easyeda/read_hi_pro.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10674) +++ trunk/src/plugins/io_easyeda/read_hi_pro.c (revision 10675) @@ -917,8 +917,15 @@ typedef struct { char *dir; unsigned is_sym:1; + + /* sym load */ DIR *dr; char *next_fn; + + /* bundled seet load */ + unsigned sheet_loader_inited:1; + vts0_t pro_sheets; /* list of name,filename pairs of all sheets */ + vts0_t pro_syms; /* list of name,filename pairs of all syms */ } easypro_bundle_t; /* read next dirent and set bnd->next_fn; skip over . and .. and hidden files */ @@ -986,9 +993,144 @@ return (de == NULL) ? 1 : 0; } -static int easypro_load_zip_sheet(easypro_bundle_t *bnd, csch_sheet_t *dst) + + +/* read the project file and map sheets and symbols to load */ +static int easypro_load_zip_sheet_init(easypro_bundle_t *bnd, csch_sheet_t *sheet) { - rnd_message(RND_MSG_ERROR, "TODO: can't load sheets from zip yet"); + char *fn, *sname = NULL; + char *user_name = NULL; /* user readable sheet name or symbol title */ + njson_sem_ctx_t jctx = {0}; + FILE *f; + enum {M_MISC, M_SCH, M_SYM} main = M_MISC; + int level = 0, c, res = 0, sch_id= -1; + njson_sem_ev_t ev; + + fn = rnd_concat(bnd->dir, "/project.json", NULL); + f = rnd_fopen(&sheet->hidlib, fn, "r"); + if (f == NULL) { + rnd_message(RND_MSG_ERROR, "easypro sheet init: failed to open '%s' for read\n", fn); + free(fn); + return -1; + } + + + /* parse project.json and remember sheets and syms */ + while((c = fgetc(f)) != 0) { + njson_ev_t ev = njson_sem_push(&jctx, c); + + if (ev == NJSON_SEM_EV_eof) break; + if (ev == NJSON_SEM_EV_error) { + rnd_message(RND_MSG_ERROR, "easypro sheet init: project.json parse error: %s at %ld:%ld\n", jctx.njs.error, jctx.njs.lineno, jctx.njs.col); + error:; + res = -1; + break; + } + + switch(ev) { + case NJSON_SEM_EV_more: continue; + case NJSON_SEM_EV_eof: case NJSON_SEM_EV_error: break; /* can't happen */ + case NJSON_SEM_EV_OBJECT_BEGIN: + if (level == 1) { + if (strcmp(jctx.name, "schematics") == 0) main = M_SCH; + else if (strcmp(jctx.name, "symbols") == 0) main = M_SYM; + } + if ((level == 2) && ((main == M_SYM) || (main == M_SCH))) { + if (sname != NULL) free(sname); + 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, main, jctx.name);*/ + break; + case NJSON_SEM_EV_OBJECT_END: + case NJSON_SEM_EV_ARRAY_END: + if ((level == 5) && (main == M_SCH)) { + /* finished reading a schematic block */ + rnd_trace("!sch flush! sname=%s uname=%s id=%d\n", sname, user_name, sch_id); + if (user_name != NULL) free(user_name); + user_name = NULL; + sch_id = -1; + } + if ((level == 3) && (main == M_SYM)) { + /* finished reading a symbol block */ + rnd_trace("!sym flush! sname=%s title=%s\n", sname, user_name); + if (user_name != NULL) free(user_name); + user_name = NULL; + } + level--; + if (level == 1) main = M_MISC; + break; + + case NJSON_SEM_EV_ATOMIC: + switch(main) { + case M_SCH: + if ((level == 3) && (strcmp(jctx.name, "name") == 0)) { + /* replace user-unreadable long uid with use readable name - however, it's not necessarily unique */ + if (jctx.type != NJSON_SEM_TYPE_STRING) { + rnd_message(RND_MSG_ERROR, "easypro sheet init: project.json parse error: sch name must be a string at %ld:%ld\n", jctx.njs.lineno, jctx.njs.col); + goto error; + } + free(sname); + sname = rnd_strdup(jctx.value.string); + break; + } + + if (level != 5) break; + /* reading items of a schematic block */ +/* rnd_trace(" [%d] sch atom: %s\n", level, jctx.name);*/ + if (strcmp(jctx.name, "id") == 0) { + if (jctx.type != NJSON_SEM_TYPE_NUMBER) { + rnd_message(RND_MSG_ERROR, "easypro sheet init: project.json parse error: sch id must be a number at %ld:%ld\n", jctx.njs.lineno, jctx.njs.col); + goto error; + } + sch_id = jctx.value.number; + } + if (strcmp(jctx.name, "name") == 0) { + if (jctx.type != NJSON_SEM_TYPE_STRING) { + rnd_message(RND_MSG_ERROR, "easypro sheet init: project.json parse error: sheet name 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; + 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; + } + } + + /* cleanup and return */ + if (sname != NULL) free(sname); + if (user_name != NULL) free(user_name); + njson_sem_uninit(&jctx); + fclose(f); + free(fn); + return res; +} + +static int easypro_load_zip_sheet(easypro_bundle_t *bnd, csch_sheet_t *sheet) +{ + if (!bnd->sheet_loader_inited) { + if (easypro_load_zip_sheet_init(bnd, sheet) != 0) + return -1; + } + return -1; } Index: trunk/src/plugins/io_easyeda/read_low_std.c =================================================================== --- trunk/src/plugins/io_easyeda/read_low_std.c (revision 10674) +++ trunk/src/plugins/io_easyeda/read_low_std.c (revision 10675) @@ -31,6 +31,7 @@ #include #include +#include #include #include