Index: trunk/src/plugins/io_easyeda/easyeda.sphash =================================================================== --- trunk/src/plugins/io_easyeda/easyeda.sphash (revision 10651) +++ trunk/src/plugins/io_easyeda/easyeda.sphash (revision 10652) @@ -5,6 +5,7 @@ ATTR BEZIER CIRCLE +Contributor DOCTYPE ELLIPSE FONTSTYLE @@ -11,11 +12,15 @@ GROUP HEAD LINESTYLE +Manufacturer +Manufacturer Part OBJ PART PIN POLY RECT +Supplier +Supplier Part TEXT arc arrowhead @@ -68,6 +73,7 @@ junction label line +link locked mark maxId @@ -84,6 +90,7 @@ origin_y originX originY +package path part_id part_type @@ -95,6 +102,7 @@ polyline polygon portOfADImportHack +pre rect rot locked Index: trunk/src/plugins/io_easyeda/read_hi_std.c =================================================================== --- trunk/src/plugins/io_easyeda/read_hi_std.c (revision 10651) +++ trunk/src/plugins/io_easyeda/read_hi_std.c (revision 10652) @@ -850,7 +850,7 @@ long n; if (nd->type != GDOM_ARRAY) { - error_at(ctx, nd, ("schematics/shape is not an array\n")); + error_at(ctx, nd, ("schematics/shape or symbol/shape is not an array\n")); return -1; } @@ -860,7 +860,7 @@ } else - warn_at(ctx, ctx->root, ("schematics without any shape\n")); + warn_at(ctx, ctx->root, ("schematics or symbol without any shape\n")); return 0; } @@ -908,6 +908,47 @@ return res; } +static csch_cgrp_t *easystd_parse_grp(read_ctx_t *ctx, gdom_node_t *sym_root) +{ + 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) { + ctx->pass = 1; + rv = easystd_parse_shapes(ctx, resgrp, shapes); + } + if (rv == 0) { + ctx->pass = 2; + rv = easystd_parse_shapes(ctx, resgrp, shapes); + } + + /* load metadata */ + if (rv == 0) { + TODO("load attribs from the header"); + } + + if (rv == 0) { + csch_cgrp_update(ctx->sheet, resgrp, 1); + csch_sheet_bbox_update(ctx->sheet); + } + else { + csch_cgrp_free(resgrp); + resgrp = NULL; + } + + + return resgrp; +} + static int easystd_get_doctype(char *stray, FILE *f, char *buf, long buf_len) { char *line = stray, *end; @@ -1014,7 +1055,34 @@ /* IO API function (load symbol from lib) */ csch_cgrp_t *io_easystd_load_grp(FILE *f, const char *fn, const char *fmt, csch_sheet_t *sheet) { - rnd_trace("std load fail %s\n", fn); + read_ctx_t ctx = {0}; + csch_cgrp_t *grp; + + if (htip_get(&sheet->direct.id2obj, 1) != NULL) { + rnd_message(RND_MSG_ERROR, "Error loading '%s': there's already a group1 in destination sheet\n", fn); + return NULL; + } + + 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 NULL; + } + + alien_setup(&ctx); + + grp = easystd_parse_grp(&ctx, ctx.root); + 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; + } + return NULL; } @@ -1071,7 +1139,7 @@ easystd_bundle_t *bnd = calloc(sizeof(easystd_bundle_t), 1); rewind(f); - bnd->root = easystd_low_parse(f); + bnd->root = easystd_low_parse(f, 0); if (bnd->root == NULL) goto quit; Index: trunk/src/plugins/io_easyeda/read_low_std.c =================================================================== --- trunk/src/plugins/io_easyeda/read_low_std.c (revision 10651) +++ trunk/src/plugins/io_easyeda/read_low_std.c (revision 10652) @@ -906,16 +906,11 @@ return -1; } -/* Replace string encoded nodes with dom subtrees */ -static void parse_sch_strs(gdom_node_t *sch) +static void parse_sch_shape_canvas(gdom_node_t *data_str) { - gdom_node_t *shape, *canvas, *data_str; + gdom_node_t *shape, *canvas; long n; - data_str = gdom_hash_get(sch, easy_dataStr); - if (data_str == NULL) - return; - shape = gdom_hash_get(data_str, easy_shape); if ((shape != NULL) && (shape->type == GDOM_ARRAY)) for(n = 0; n < shape->value.array.used; n++) @@ -926,6 +921,18 @@ parse_canvas(&canvas); } +/* Replace string encoded nodes with dom subtrees */ +static void parse_sch_strs(gdom_node_t *sch) +{ + gdom_node_t *data_str; + + data_str = gdom_hash_get(sch, easy_dataStr); + if (data_str == NULL) + return; + + parse_sch_shape_canvas(data_str); +} + long easyeda_str2name(const char *str) { long res = easy_sphash(str); @@ -934,7 +941,7 @@ return res; } -gdom_node_t *easystd_low_sch_parse(FILE *f) +gdom_node_t *easystd_low_sch_parse(FILE *f, int is_sym) { gdom_node_t *root, *schs; @@ -944,12 +951,16 @@ return NULL; /* parse strings into dom subtrees */ - schs = gdom_hash_get(root, easy_schematics); - if ((schs != NULL) && (schs->type == GDOM_ARRAY)) { - long n; - for(n = 0; n < schs->value.array.used; n++) - parse_sch_strs(schs->value.array.child[n]); + if (!is_sym) { + schs = gdom_hash_get(root, easy_schematics); + if ((schs != NULL) && (schs->type == GDOM_ARRAY)) { + long n; + for(n = 0; n < schs->value.array.used; n++) + parse_sch_strs(schs->value.array.child[n]); + } } + else + parse_sch_shape_canvas(root); return root; } @@ -969,9 +980,9 @@ fprintf(f, "\n"); } -gdom_node_t *easystd_low_parse(FILE *f) +gdom_node_t *easystd_low_parse(FILE *f, int is_sym) { - gdom_node_t *tree = easystd_low_sch_parse(f); + gdom_node_t *tree = easystd_low_sch_parse(f, is_sym); if (io_easyeda_conf.plugins.io_easyeda.debug.dump_dom) easyeda_dump_tree(stdout, tree); Index: trunk/src/plugins/io_easyeda/read_low_std.h =================================================================== --- trunk/src/plugins/io_easyeda/read_low_std.h (revision 10651) +++ trunk/src/plugins/io_easyeda/read_low_std.h (revision 10652) @@ -4,7 +4,7 @@ /* Parse an open file into a gdom tree; call gdom_free() to discard it after use. Works on "easyeda std" sch files */ -gdom_node_t *easystd_low_parse(FILE *f); +gdom_node_t *easystd_low_parse(FILE *f, int is_sym);