Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 3305) +++ trunk/scconfig/plugins.h (revision 3306) @@ -30,6 +30,7 @@ plugin_def("io_geda", "gEDA schematics and symbols", sbuildin, 1) plugin_def("io_lihata", "lihata schematics and symbols", sbuildin, 1) plugin_def("io_tinycad", "TinyCAD schematics", sbuildin, 1) +plugin_def("lib_alien", "alien format helper", sbuildin, 1) plugin_header("\nGUI:\n") plugin_def("gui", "Graphical User Interface", sbuildin, 1) @@ -37,5 +38,6 @@ plugin_dep("gui", "lib_hid_common") +plugin_dep("io_geda", "lib_alien") plugin_dep("propedit", "sch_dialogs") plugin_dep("sch_dialogs", "lib_hid_common") Index: trunk/src/plugins/io_geda/read_helper.h =================================================================== --- trunk/src/plugins/io_geda/read_helper.h (revision 3305) +++ trunk/src/plugins/io_geda/read_helper.h (nonexistent) @@ -1,61 +0,0 @@ -/* - * COPYRIGHT - * - * cschem - modular/flexible schematics editor - alien file format helpers - * Copyright (C) 2022 Tibor 'Igor2' Palinkas - * - * (Supported by NLnet NGI0 PET Fund in 2022) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/cschem - * lead developer: email to cschem (at) igor2.repo.hu - * mailing list: cschem (at) list.repo.hu (send "subscribe") - */ - -#include - -typedef struct csch_alien_read_ctx_s { - csch_sheet_t *sheet; - csch_source_arg_t src; - double coord_factor; -} csch_alien_read_ctx_t; - -/* Set up ctx->sheet: - - if pen is non-zero, copy default pens -*/ -void csch_alien_sheet_setup(csch_alien_read_ctx_t *ctx, int pen); - -/* Return the group attributes should be set in for obj; may create a new - group around obj. */ -csch_cgrp_t *csch_alien_attr_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj); - -/* If obj is not a group, create a group around it and return it (else - return obj). Useful when attributes are to be attached. Obj ptr - may change in the process (when mvoed into a new group). */ -csch_cgrp_t *csch_alien_convert_to_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj); - -csch_chdr_t *csch_alien_mknet(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2); -csch_chdr_t *csch_alien_mkline(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *penname); -csch_chdr_t *csch_alien_mkarc(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double cx, double cy, double r, double sa, double da, const char *penname); -csch_chdr_t *csch_alien_mkrect(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *stroke_penname, const char *fill_penname); -csch_chdr_t *csch_alien_mkpin_line(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2); -csch_chdr_t *csch_alien_mktext(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x, double y, const char *penname); - -void csch_alien_mkbezier(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char *penname); - - - Index: trunk/src/plugins/io_geda/read_helper.c =================================================================== --- trunk/src/plugins/io_geda/read_helper.c (revision 3305) +++ trunk/src/plugins/io_geda/read_helper.c (nonexistent) @@ -1,295 +0,0 @@ -/* - * COPYRIGHT - * - * cschem - modular/flexible schematics editor - alien file format helpers - * Copyright (C) 2022 Tibor 'Igor2' Palinkas - * - * (Supported by NLnet NGI0 PET Fund in 2022) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/cschem - * lead developer: email to cschem (at) igor2.repo.hu - * mailing list: cschem (at) list.repo.hu (send "subscribe") - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include - -#include -#include - -#include "read_helper.h" - -csch_chdr_t *csch_alien_mknet(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2) -{ - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x1 *= ctx->coord_factor; - y1 *= ctx->coord_factor; - x2 *= ctx->coord_factor; - y2 *= ctx->coord_factor; - } - - if (parent != &ctx->sheet->direct) { - rnd_message(RND_MSG_ERROR, "csch_alien_mknet(): can not create wire within a group at the moment\n"); - return NULL; - } - - return csch_wirenet_draw(ctx->sheet, csch_comm_str(ctx->sheet, "wire", 1), rnd_round(x1), rnd_round(y1), rnd_round(x2), rnd_round(y2)); -} - -csch_chdr_t *csch_alien_mkline(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *penname) -{ - csch_line_t *line; - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x1 *= ctx->coord_factor; - y1 *= ctx->coord_factor; - x2 *= ctx->coord_factor; - y2 *= ctx->coord_factor; - } - - line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - line->spec.p1.x = rnd_round(x1); - line->spec.p1.y = rnd_round(y1); - line->spec.p2.x = rnd_round(x2); - line->spec.p2.y = rnd_round(y2); - line->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); - - return &line->hdr; -} - -csch_inline void poly_line(csch_cpoly_t *poly, csch_coord_t x1, csch_coord_t y1, csch_coord_t x2, csch_coord_t y2) -{ - csch_coutline_t *dst = csch_vtcoutline_alloc_append(&poly->outline, 1); - csch_line_t *line = &dst->line; - - line->hdr.type = CSCH_CTYPE_LINE; - line->spec.p1.x = x1; line->spec.p1.y = y1; - line->spec.p2.x = x2; line->spec.p2.y = y2; -} - -csch_chdr_t *csch_alien_mkrect(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *stroke_penname, const char *fill_penname) -{ - csch_cpoly_t *poly; - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x1 = rnd_round(x1 * ctx->coord_factor); - y1 = rnd_round(y1 * ctx->coord_factor); - x2 = rnd_round(x2 * ctx->coord_factor); - y2 = rnd_round(y2 * ctx->coord_factor); - } - - poly = csch_cpoly_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - poly_line(poly, x1, y1, x1, y2); - poly_line(poly, x1, y2, x2, y2); - poly_line(poly, x2, y2, x2, y1); - poly_line(poly, x2, y1, x1, y1); - - if (stroke_penname != NULL) { - poly->hdr.stroke_name = csch_comm_str(ctx->sheet, stroke_penname, 1); - poly->has_stroke = 1; - } - else - poly->has_stroke = 0; - - if (fill_penname != NULL) { - poly->hdr.fill_name = csch_comm_str(ctx->sheet, fill_penname, 1); - poly->has_fill = 1; - } - else - poly->has_fill = 0; - - return &poly->hdr; -} - -csch_chdr_t *csch_alien_mkpin_line(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2) -{ - csch_cgrp_t *pin; - csch_line_t *line; - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x1 *= ctx->coord_factor; - y1 *= ctx->coord_factor; - x2 *= ctx->coord_factor; - y2 *= ctx->coord_factor; - } - - pin = csch_cgrp_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - csch_cobj_attrib_set(ctx->sheet, &pin->hdr, CSCH_ATP_HARDWIRED, "role", "terminal", ctx->src); - - line = csch_line_alloc(ctx->sheet, pin, csch_oid_new(ctx->sheet, pin)); - line->spec.p1.x = rnd_round(x1); - line->spec.p1.y = rnd_round(y1); - line->spec.p2.x = rnd_round(x2); - line->spec.p2.y = rnd_round(y2); - line->hdr.stroke_name = csch_comm_str(ctx->sheet, "term-primary", 1); - - return &pin->hdr; -} - -void csch_alien_mkbezier(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char *penname) -{ - double len, step, t; - double lx, ly, x, y; - csch_line_t *line; - csch_comm_str_t pen = csch_comm_str(ctx->sheet, penname, 1); - - len = rnd_distance(x1, y1, x2, y2) + rnd_distance(x2, y2, x3, y3) + rnd_distance(x3, y3, x4, y4); - step = (1000.0 / (len + 3000.0)) / 5.0; - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x1 *= ctx->coord_factor; - y1 *= ctx->coord_factor; - x2 *= ctx->coord_factor; - y2 *= ctx->coord_factor; - x3 *= ctx->coord_factor; - y3 *= ctx->coord_factor; - x4 *= ctx->coord_factor; - y4 *= ctx->coord_factor; - } - - - lx = x1; ly = y1; - - for(t = step; t < 1; t += step) { - double mt = 1-t; - double a = mt*mt*mt, b = 3*mt*mt*t, c = 3*mt*t*t, d = t*t*t; - /* B(t) = (1-t)^3*P0 + 3*(1-t)^2*t*P1 + 3*(1-t)*t^2*P2 + t^3*P3 @ 0 <= t <= 1 */ - - x = a*x1 + b*x2 + c*x3 + d*x4; - y = a*y1 + b*y2 + c*y3 + d*y4; - - if ((lx != x) || (ly != y)) { - line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - line->spec.p1.x = rnd_round(lx); - line->spec.p1.y = rnd_round(ly); - line->spec.p2.x = rnd_round(x); - line->spec.p2.y = rnd_round(y); - line->hdr.stroke_name = pen; - lx = x; - ly = y; - } - } - - if ((lx != x4) || (ly != y4)) { - line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - line->spec.p1.x = rnd_round(lx); - line->spec.p1.y = rnd_round(ly); - line->spec.p2.x = rnd_round(x4); - line->spec.p2.y = rnd_round(y4); - line->hdr.stroke_name = pen; - } -} - - -csch_chdr_t *csch_alien_mkarc(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double cx, double cy, double r, double sa, double da, const char *penname) -{ - csch_arc_t *arc; - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - cx *= ctx->coord_factor; - cy *= ctx->coord_factor; - r *= ctx->coord_factor; - } - - arc = csch_arc_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - arc->spec.c.x = rnd_round(cx); - arc->spec.c.y = rnd_round(cy); - arc->spec.r = rnd_round(r); - arc->spec.start = sa / RND_RAD_TO_DEG; - arc->spec.delta = da / RND_RAD_TO_DEG; - arc->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); - - return &arc->hdr; -} - -csch_chdr_t *csch_alien_mktext(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x, double y, const char *penname) -{ - csch_text_t *text = csch_text_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); - - if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { - x *= ctx->coord_factor; - y *= ctx->coord_factor; - } - - text->spec1.x = x; - text->spec1.y = y; - text->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); - - return &text->hdr; -} - - -void csch_alien_sheet_setup(csch_alien_read_ctx_t *ctx, int pen) -{ - if (pen != 0) { /* create temp new sheet only if we are to do anything */ - csch_sheet_t *tmp = sch_rnd_sheet_new(ctx->sheet->parent); - if (pen != 0) { - htip_entry_t *e; - for(e = htip_first(&tmp->direct.id2obj); e != NULL; e = htip_next(&tmp->direct.id2obj, e)) { - csch_cpen_t *p = e->value; - if (p->hdr.type == CSCH_CTYPE_PEN) - csch_pen_dup(ctx->sheet, &ctx->sheet->direct, p); - } - } -TODO("remove sheet from project: vtp0_append(&prj->sheets, sheet)"); -/* csch_sheet_free(tmp);*/ - } -} - -csch_cgrp_t *csch_alien_convert_to_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj) -{ - csch_cgrp_t *grp; - csch_chdr_t *newo; - - if (csch_obj_is_grp(*obj)) - return (csch_cgrp_t *)(*obj); - - grp = csch_cgrp_alloc(ctx->sheet, (*obj)->parent, csch_oid_new(ctx->sheet, (*obj)->parent)); - - csch_cnc_remove(ctx->sheet, (*obj)); - newo = csch_cobj_dup(ctx->sheet, grp, (*obj), 0); - csch_cobj_update(ctx->sheet, newo, 0); -/* csch_op_inserted(sheet, dst, newo);*/ - *obj = newo; - return grp; -} - -csch_cgrp_t *csch_alien_attr_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj) -{ - csch_cgrp_t *parent = (*obj)->parent; - - if (csch_obj_is_grp(*obj)) - return (csch_cgrp_t *)(*obj); - - if ((parent->role == CSCH_ROLE_WIRE_NET) || (parent->role == CSCH_ROLE_SYMBOL)) - return parent; - - return csch_alien_convert_to_grp(ctx, obj); -} Index: trunk/src/plugins/io_geda/Plug.tmpasm =================================================================== --- trunk/src/plugins/io_geda/Plug.tmpasm (revision 3305) +++ trunk/src/plugins/io_geda/Plug.tmpasm (revision 3306) @@ -2,7 +2,6 @@ put /local/pcb/mod/OBJS [@ $(PLUGDIR)/io_geda/io_geda.o $(PLUGDIR)/io_geda/read.o - $(PLUGDIR)/io_geda/read_helper.o @] put /local/pcb/mod/CONFFILE {io_geda.conf} Index: trunk/src/plugins/io_geda/io_geda.pup =================================================================== --- trunk/src/plugins/io_geda/io_geda.pup (revision 3305) +++ trunk/src/plugins/io_geda/io_geda.pup (revision 3306) @@ -5,5 +5,6 @@ $fmt-feature-r geda cschem schematics (v2) $fmt-feature-r geda cschem symbol (v1) $package alien +dep lib_alien default buildin autoload 1 Index: trunk/src/plugins/io_geda/read.c =================================================================== --- trunk/src/plugins/io_geda/read.c (revision 3305) +++ trunk/src/plugins/io_geda/read.c (revision 3306) @@ -52,7 +52,7 @@ #include #include -#include "read_helper.h" +#include #include "io_geda_conf.h" extern conf_io_geda_t io_geda_conf; Index: trunk/src/plugins/lib_alien/Makefile =================================================================== --- trunk/src/plugins/lib_alien/Makefile (nonexistent) +++ trunk/src/plugins/lib_alien/Makefile (revision 3306) @@ -0,0 +1,2 @@ +all: + cd ../../sch-rnd && make mod_lib_alien Index: trunk/src/plugins/lib_alien/Plug.tmpasm =================================================================== --- trunk/src/plugins/lib_alien/Plug.tmpasm (nonexistent) +++ trunk/src/plugins/lib_alien/Plug.tmpasm (revision 3306) @@ -0,0 +1,11 @@ +put /local/pcb/mod {lib_alien} +put /local/pcb/mod/OBJS [@ + $(PLUGDIR)/lib_alien/lib_alien.o + $(PLUGDIR)/lib_alien/read_helper.o +@] + +switch /local/pcb/lib_alien/controls + case {buildin} include /local/pcb/tmpasm/buildin; end; + case {plugin} include /local/pcb/tmpasm/plugin; end; + case {disable} include /local/pcb/tmpasm/disable; end; +end Index: trunk/src/plugins/lib_alien/lib_alien.c =================================================================== --- trunk/src/plugins/lib_alien/lib_alien.c (nonexistent) +++ trunk/src/plugins/lib_alien/lib_alien.c (revision 3306) @@ -0,0 +1,40 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - libcschem (gEDA format support) + * Copyright (C) 2022 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/cschem + * lead developer: email to cschem (at) igor2.repo.hu + * mailing list: cschem (at) list.repo.hu (send "subscribe") + */ + + +#include + +int pplg_check_ver_lib_alien(int ver_needed) { return 0; } + +void pplg_uninit_lib_alien(void) +{ +} + +int pplg_init_lib_alien(void) +{ + return 0; +} + Index: trunk/src/plugins/lib_alien/lib_alien.pup =================================================================== --- trunk/src/plugins/lib_alien/lib_alien.pup (nonexistent) +++ trunk/src/plugins/lib_alien/lib_alien.pup (revision 3306) @@ -0,0 +1,7 @@ +$class io +$short alien format helper +$long Format-independent helper functions for reading alien files +$state WIP +$package alien +default buildin +autoload 1 Index: trunk/src/plugins/lib_alien/read_helper.c =================================================================== --- trunk/src/plugins/lib_alien/read_helper.c (nonexistent) +++ trunk/src/plugins/lib_alien/read_helper.c (revision 3306) @@ -0,0 +1,295 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - alien file format helpers + * Copyright (C) 2022 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 PET Fund in 2022) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/cschem + * lead developer: email to cschem (at) igor2.repo.hu + * mailing list: cschem (at) list.repo.hu (send "subscribe") + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include + +#include "read_helper.h" + +csch_chdr_t *csch_alien_mknet(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2) +{ + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x1 *= ctx->coord_factor; + y1 *= ctx->coord_factor; + x2 *= ctx->coord_factor; + y2 *= ctx->coord_factor; + } + + if (parent != &ctx->sheet->direct) { + rnd_message(RND_MSG_ERROR, "csch_alien_mknet(): can not create wire within a group at the moment\n"); + return NULL; + } + + return csch_wirenet_draw(ctx->sheet, csch_comm_str(ctx->sheet, "wire", 1), rnd_round(x1), rnd_round(y1), rnd_round(x2), rnd_round(y2)); +} + +csch_chdr_t *csch_alien_mkline(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *penname) +{ + csch_line_t *line; + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x1 *= ctx->coord_factor; + y1 *= ctx->coord_factor; + x2 *= ctx->coord_factor; + y2 *= ctx->coord_factor; + } + + line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + line->spec.p1.x = rnd_round(x1); + line->spec.p1.y = rnd_round(y1); + line->spec.p2.x = rnd_round(x2); + line->spec.p2.y = rnd_round(y2); + line->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); + + return &line->hdr; +} + +csch_inline void poly_line(csch_cpoly_t *poly, csch_coord_t x1, csch_coord_t y1, csch_coord_t x2, csch_coord_t y2) +{ + csch_coutline_t *dst = csch_vtcoutline_alloc_append(&poly->outline, 1); + csch_line_t *line = &dst->line; + + line->hdr.type = CSCH_CTYPE_LINE; + line->spec.p1.x = x1; line->spec.p1.y = y1; + line->spec.p2.x = x2; line->spec.p2.y = y2; +} + +csch_chdr_t *csch_alien_mkrect(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *stroke_penname, const char *fill_penname) +{ + csch_cpoly_t *poly; + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x1 = rnd_round(x1 * ctx->coord_factor); + y1 = rnd_round(y1 * ctx->coord_factor); + x2 = rnd_round(x2 * ctx->coord_factor); + y2 = rnd_round(y2 * ctx->coord_factor); + } + + poly = csch_cpoly_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + poly_line(poly, x1, y1, x1, y2); + poly_line(poly, x1, y2, x2, y2); + poly_line(poly, x2, y2, x2, y1); + poly_line(poly, x2, y1, x1, y1); + + if (stroke_penname != NULL) { + poly->hdr.stroke_name = csch_comm_str(ctx->sheet, stroke_penname, 1); + poly->has_stroke = 1; + } + else + poly->has_stroke = 0; + + if (fill_penname != NULL) { + poly->hdr.fill_name = csch_comm_str(ctx->sheet, fill_penname, 1); + poly->has_fill = 1; + } + else + poly->has_fill = 0; + + return &poly->hdr; +} + +csch_chdr_t *csch_alien_mkpin_line(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2) +{ + csch_cgrp_t *pin; + csch_line_t *line; + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x1 *= ctx->coord_factor; + y1 *= ctx->coord_factor; + x2 *= ctx->coord_factor; + y2 *= ctx->coord_factor; + } + + pin = csch_cgrp_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + csch_cobj_attrib_set(ctx->sheet, &pin->hdr, CSCH_ATP_HARDWIRED, "role", "terminal", ctx->src); + + line = csch_line_alloc(ctx->sheet, pin, csch_oid_new(ctx->sheet, pin)); + line->spec.p1.x = rnd_round(x1); + line->spec.p1.y = rnd_round(y1); + line->spec.p2.x = rnd_round(x2); + line->spec.p2.y = rnd_round(y2); + line->hdr.stroke_name = csch_comm_str(ctx->sheet, "term-primary", 1); + + return &pin->hdr; +} + +void csch_alien_mkbezier(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char *penname) +{ + double len, step, t; + double lx, ly, x, y; + csch_line_t *line; + csch_comm_str_t pen = csch_comm_str(ctx->sheet, penname, 1); + + len = rnd_distance(x1, y1, x2, y2) + rnd_distance(x2, y2, x3, y3) + rnd_distance(x3, y3, x4, y4); + step = (1000.0 / (len + 3000.0)) / 5.0; + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x1 *= ctx->coord_factor; + y1 *= ctx->coord_factor; + x2 *= ctx->coord_factor; + y2 *= ctx->coord_factor; + x3 *= ctx->coord_factor; + y3 *= ctx->coord_factor; + x4 *= ctx->coord_factor; + y4 *= ctx->coord_factor; + } + + + lx = x1; ly = y1; + + for(t = step; t < 1; t += step) { + double mt = 1-t; + double a = mt*mt*mt, b = 3*mt*mt*t, c = 3*mt*t*t, d = t*t*t; + /* B(t) = (1-t)^3*P0 + 3*(1-t)^2*t*P1 + 3*(1-t)*t^2*P2 + t^3*P3 @ 0 <= t <= 1 */ + + x = a*x1 + b*x2 + c*x3 + d*x4; + y = a*y1 + b*y2 + c*y3 + d*y4; + + if ((lx != x) || (ly != y)) { + line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + line->spec.p1.x = rnd_round(lx); + line->spec.p1.y = rnd_round(ly); + line->spec.p2.x = rnd_round(x); + line->spec.p2.y = rnd_round(y); + line->hdr.stroke_name = pen; + lx = x; + ly = y; + } + } + + if ((lx != x4) || (ly != y4)) { + line = csch_line_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + line->spec.p1.x = rnd_round(lx); + line->spec.p1.y = rnd_round(ly); + line->spec.p2.x = rnd_round(x4); + line->spec.p2.y = rnd_round(y4); + line->hdr.stroke_name = pen; + } +} + + +csch_chdr_t *csch_alien_mkarc(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double cx, double cy, double r, double sa, double da, const char *penname) +{ + csch_arc_t *arc; + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + cx *= ctx->coord_factor; + cy *= ctx->coord_factor; + r *= ctx->coord_factor; + } + + arc = csch_arc_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + arc->spec.c.x = rnd_round(cx); + arc->spec.c.y = rnd_round(cy); + arc->spec.r = rnd_round(r); + arc->spec.start = sa / RND_RAD_TO_DEG; + arc->spec.delta = da / RND_RAD_TO_DEG; + arc->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); + + return &arc->hdr; +} + +csch_chdr_t *csch_alien_mktext(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x, double y, const char *penname) +{ + csch_text_t *text = csch_text_alloc(ctx->sheet, parent, csch_oid_new(ctx->sheet, parent)); + + if ((ctx->coord_factor != 0) && (ctx->coord_factor != 1)) { + x *= ctx->coord_factor; + y *= ctx->coord_factor; + } + + text->spec1.x = x; + text->spec1.y = y; + text->hdr.stroke_name = csch_comm_str(ctx->sheet, penname, 1); + + return &text->hdr; +} + + +void csch_alien_sheet_setup(csch_alien_read_ctx_t *ctx, int pen) +{ + if (pen != 0) { /* create temp new sheet only if we are to do anything */ + csch_sheet_t *tmp = sch_rnd_sheet_new(ctx->sheet->parent); + if (pen != 0) { + htip_entry_t *e; + for(e = htip_first(&tmp->direct.id2obj); e != NULL; e = htip_next(&tmp->direct.id2obj, e)) { + csch_cpen_t *p = e->value; + if (p->hdr.type == CSCH_CTYPE_PEN) + csch_pen_dup(ctx->sheet, &ctx->sheet->direct, p); + } + } +TODO("remove sheet from project: vtp0_append(&prj->sheets, sheet)"); +/* csch_sheet_free(tmp);*/ + } +} + +csch_cgrp_t *csch_alien_convert_to_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj) +{ + csch_cgrp_t *grp; + csch_chdr_t *newo; + + if (csch_obj_is_grp(*obj)) + return (csch_cgrp_t *)(*obj); + + grp = csch_cgrp_alloc(ctx->sheet, (*obj)->parent, csch_oid_new(ctx->sheet, (*obj)->parent)); + + csch_cnc_remove(ctx->sheet, (*obj)); + newo = csch_cobj_dup(ctx->sheet, grp, (*obj), 0); + csch_cobj_update(ctx->sheet, newo, 0); +/* csch_op_inserted(sheet, dst, newo);*/ + *obj = newo; + return grp; +} + +csch_cgrp_t *csch_alien_attr_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj) +{ + csch_cgrp_t *parent = (*obj)->parent; + + if (csch_obj_is_grp(*obj)) + return (csch_cgrp_t *)(*obj); + + if ((parent->role == CSCH_ROLE_WIRE_NET) || (parent->role == CSCH_ROLE_SYMBOL)) + return parent; + + return csch_alien_convert_to_grp(ctx, obj); +} Index: trunk/src/plugins/lib_alien/read_helper.h =================================================================== --- trunk/src/plugins/lib_alien/read_helper.h (nonexistent) +++ trunk/src/plugins/lib_alien/read_helper.h (revision 3306) @@ -0,0 +1,61 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - alien file format helpers + * Copyright (C) 2022 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 PET Fund in 2022) + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/cschem + * lead developer: email to cschem (at) igor2.repo.hu + * mailing list: cschem (at) list.repo.hu (send "subscribe") + */ + +#include + +typedef struct csch_alien_read_ctx_s { + csch_sheet_t *sheet; + csch_source_arg_t src; + double coord_factor; +} csch_alien_read_ctx_t; + +/* Set up ctx->sheet: + - if pen is non-zero, copy default pens +*/ +void csch_alien_sheet_setup(csch_alien_read_ctx_t *ctx, int pen); + +/* Return the group attributes should be set in for obj; may create a new + group around obj. */ +csch_cgrp_t *csch_alien_attr_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj); + +/* If obj is not a group, create a group around it and return it (else + return obj). Useful when attributes are to be attached. Obj ptr + may change in the process (when mvoed into a new group). */ +csch_cgrp_t *csch_alien_convert_to_grp(csch_alien_read_ctx_t *ctx, csch_chdr_t **obj); + +csch_chdr_t *csch_alien_mknet(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2); +csch_chdr_t *csch_alien_mkline(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *penname); +csch_chdr_t *csch_alien_mkarc(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double cx, double cy, double r, double sa, double da, const char *penname); +csch_chdr_t *csch_alien_mkrect(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, const char *stroke_penname, const char *fill_penname); +csch_chdr_t *csch_alien_mkpin_line(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2); +csch_chdr_t *csch_alien_mktext(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x, double y, const char *penname); + +void csch_alien_mkbezier(csch_alien_read_ctx_t *ctx, csch_cgrp_t *parent, double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4, const char *penname); + + + Index: trunk/src/plugins/plugins_ALL.tmpasm =================================================================== --- trunk/src/plugins/plugins_ALL.tmpasm (revision 3305) +++ trunk/src/plugins/plugins_ALL.tmpasm (revision 3306) @@ -7,6 +7,7 @@ include {../src/plugins/io_geda/Plug.tmpasm} include {../src/plugins/io_lihata/Plug.tmpasm} include {../src/plugins/io_tinycad/Plug.tmpasm} +include {../src/plugins/lib_alien/Plug.tmpasm} include {../src/plugins/place/Plug.tmpasm} include {../src/plugins/propedit/Plug.tmpasm} include {../src/plugins/query/Plug.tmpasm} Index: trunk/src/sch-rnd/Makefile.dep =================================================================== --- trunk/src/sch-rnd/Makefile.dep (revision 3305) +++ trunk/src/sch-rnd/Makefile.dep (revision 3306) @@ -101,23 +101,9 @@ ../libcschem/cnc_any_obj.h ../libcschem/concrete.h \ ../libcschem/operation.h ../libcschem/project.h ../libcschem/engine.h \ ../libcschem/util_parse.h ../../src_3rd/load_cache/load_cache.h \ - ../sch-rnd/buffer.h ../plugins/io_geda/read_helper.h \ + ../sch-rnd/buffer.h ../plugins/lib_alien/read_helper.h \ ../plugins/io_geda/io_geda_conf.h ../plugins/io_geda/read.h \ ../libcschem/plug_io.h ../libcschem/abstract.h -../plugins/io_geda/read_helper.o: ../plugins/io_geda/read_helper.c \ - ../libcschem/config.h ../libcschem/util_wirenet.h \ - ../libcschem/cnc_line.h ../libcschem/concrete.h \ - ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ - ../libcschem/oidpath.h ../libcschem/vtoid.h \ - ../../src_3rd/libuundo/uundo.h \ - ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ - ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ - ../libcschem/TODO.h ../libcschem/cnc_pen.h ../libcschem/cnc_grp.h \ - ../libcschem/cnc_arc.h ../libcschem/cnc_text.h \ - ../libcschem/cnc_text_dyn.h ../libcschem/cnc_poly.h \ - ../libcschem/vtcoutline.h ../libcschem/cnc_any_obj.h \ - ../libcschem/concrete.h ../libcschem/operation.h ../sch-rnd/style.h \ - ../sch-rnd/sheet.h ../plugins/io_geda/read_helper.h ../plugins/io_lihata/io_lihata.o: ../plugins/io_lihata/io_lihata.c \ ../libcschem/config.h ../libcschem/plug_io.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ @@ -171,6 +157,22 @@ ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ ../libcschem/TODO.h ../libcschem/abstract.h +../plugins/lib_alien/lib_alien.o: ../plugins/lib_alien/lib_alien.c \ + ../libcschem/config.h +../plugins/lib_alien/read_helper.o: ../plugins/lib_alien/read_helper.c \ + ../libcschem/config.h ../libcschem/util_wirenet.h \ + ../libcschem/cnc_line.h ../libcschem/concrete.h \ + ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \ + ../libcschem/oidpath.h ../libcschem/vtoid.h \ + ../../src_3rd/libuundo/uundo.h \ + ../../src_3rd/gengeo2d/typecfg_long_double.h ../../src_3rd/opc89.h \ + ../../src_3rd/gengeo2d/common.h ../../src_3rd/gengeo2d/prim.h \ + ../libcschem/TODO.h ../libcschem/cnc_pen.h ../libcschem/cnc_grp.h \ + ../libcschem/cnc_arc.h ../libcschem/cnc_text.h \ + ../libcschem/cnc_text_dyn.h ../libcschem/cnc_poly.h \ + ../libcschem/vtcoutline.h ../libcschem/cnc_any_obj.h \ + ../libcschem/concrete.h ../libcschem/operation.h ../sch-rnd/style.h \ + ../sch-rnd/sheet.h ../plugins/lib_alien/read_helper.h ../plugins/place/place.o: ../plugins/place/place.c ../libcschem/config.h \ ../libcschem/search.h ../libcschem/concrete.h \ ../libcschem/common_types.h ../libcschem/rtree.h ../libcschem/attrib.h \