Index: trunk/src/plugins/io_easyeda/read.c =================================================================== --- trunk/src/plugins/io_easyeda/read.c (revision 10654) +++ trunk/src/plugins/io_easyeda/read.c (revision 10655) @@ -55,6 +55,7 @@ #include #include #include +#include #include #include Index: trunk/src/plugins/io_easyeda/read_hi_std.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_std.c (revision 10654) +++ trunk/src/plugins/io_easyeda/read_hi_std.c (revision 10655) @@ -914,18 +914,11 @@ return res; } -static csch_cgrp_t *easystd_parse_grp(read_ctx_t *ctx, gdom_node_t *sym_root) +static csch_cgrp_t *easystd_parse_grp_(read_ctx_t *ctx, gdom_node_t *sym_root, csch_cgrp_t *resgrp) { - csch_cgrp_t *resgrp = NULL; - csch_source_arg_t *src; int rv = 0; gdom_node_t *shapes; - /* create the symbol group */ - resgrp = 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, resgrp, CSCH_ATP_HARDWIRED, "role", "symbol", src); - /* load graphics */ HASH_GET_SUBTREE(shapes, sym_root, easy_shape, GDOM_ARRAY, rv = 1;); if (rv == 0) { @@ -951,10 +944,70 @@ resgrp = NULL; } - return resgrp; } + +static csch_cgrp_t *easystd_parse_grp(read_ctx_t *ctx, gdom_node_t *sym_root) +{ + csch_source_arg_t *src; + csch_cgrp_t *resgrp = NULL; + + /* create the symbol group */ + resgrp = 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, resgrp, CSCH_ATP_HARDWIRED, "role", "symbol", src); + + return easystd_parse_grp_(ctx, sym_root, resgrp); +} + +/* Copy only standard, symbol-related pen names from the default sheet */ +static int sym_as_sheet_chk_copy_pen(void *udata, csch_sheet_t *dst, csch_cpen_t *p) +{ + if (strncmp(p->name.str, "busterm-", 8) == 0) return 1; + if (strncmp(p->name.str, "term-", 5) == 0) return 1; + if (strncmp(p->name.str, "sym-", 4) == 0) return 1; + return 0; +} + +static int easystd_load_sym_as_sheet(FILE *f, const char *fn, csch_sheet_t *sheet) +{ + read_ctx_t ctx = {0}; + int res; + csch_cgrp_t *resgrp; + + /* ctx->sheet->indirect and ctx->sheet->direct are initialized and empty */ + rnd_trace("SYM LOAD\n"); + + ctx.f = f; + ctx.fn = fn; + ctx.sheet = sheet; + ctx.root = easystd_low_parse(f, 1); + if (ctx.root == NULL) { + rnd_message(RND_MSG_ERROR, "Error loading '%s': low level 'std' parser failed\n", fn); + return -1; + } + + alien_setup(&ctx); + + resgrp = easystd_parse_grp_(&ctx, ctx.root, &sheet->direct); + + if (io_easyeda_postproc(&ctx, 0) != 0) + rnd_message(RND_MSG_ERROR, "io_easyeda: failed to postprocess newly loaded symbol\n"); + + if (ctx.root != NULL) { + gdom_free(ctx.root); + ctx.root = NULL; + } + + if (resgrp != NULL) { + sch_rnd_sheet_setup(sheet, SCH_RND_SSC_PENS | SCH_RND_SSC_PEN_MARK_DEFAULT, sym_as_sheet_chk_copy_pen, NULL); + return 0; + } + + return -1; +} + static int easystd_get_doctype(char *stray, FILE *f, char *buf, long buf_len) { char *line = stray, *end; @@ -1011,7 +1064,7 @@ if (strncmp(line, "docType\"", 8) == 0) { found |= 2; /* generic easyeda */ doctype = easystd_get_doctype(line + 8, f, line, sizeof(line)); - if ((doctype == 2) && (/*(type == CSCH_IOTYP_SHEET) ||*/ (type == CSCH_IOTYP_GROUP))) { + if ((doctype == 2) && ((type == CSCH_IOTYP_SHEET) || (type == CSCH_IOTYP_GROUP))) { *is_sym = 1; found |= 4; /* open symbols in sym edit mode or load from lib */ } @@ -1050,6 +1103,7 @@ typedef struct { gdom_node_t *root; int sheet_idx; + unsigned sym_as_sheet:1; } easystd_bundle_t; int io_easystd_test_parse(FILE *f, const char *fn, const char *fmt, csch_plug_io_type_t type) @@ -1103,6 +1157,11 @@ easystd_bundle_t *bnd = cookie; read_ctx_t ctx = {0}; + if (bnd->sym_as_sheet) { + easystd_load_sym_as_sheet(f, fn, dst); + return 1; + } + ctx.f = f; ctx.fn = fn; ctx.sheet = ctx.alien.sheet = dst; @@ -1141,6 +1200,13 @@ { int is_sym, res = io_easystd_test_parse_(f, fn, fmt, type, &is_sym); + if ((res == 0) && is_sym) { + easystd_bundle_t *bnd = calloc(sizeof(easystd_bundle_t), 1); + rewind(f); + bnd->sym_as_sheet = 1; + return bnd; + } + if ((res == 0) && !is_sym) { easystd_bundle_t *bnd = calloc(sizeof(easystd_bundle_t), 1); @@ -1168,7 +1234,8 @@ { easystd_bundle_t *bnd = cookie; - gdom_free(bnd->root); + if (bnd->root != NULL) + gdom_free(bnd->root); free(bnd); }