Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 7498) +++ trunk/scconfig/Rev.h (revision 7499) @@ -1 +1 @@ -static const int myrev = 7469; +static const int myrev = 7499; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 7498) +++ trunk/scconfig/Rev.tab (revision 7499) @@ -1,3 +1,4 @@ +7499 configure new plugin: export_spice 7469 configure new plugin for non-graphical fawk sheets 7468 configure new plugin for non-graphical tEDAx sheets 7370 configure cleanup: get rid of local "inline" defs Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 7498) +++ trunk/scconfig/plugins.h (revision 7499) @@ -32,6 +32,7 @@ plugin_def("export_lpr", "lpr exporter (printer)", sbuildin, 1) plugin_def("export_png", "export sheets to png", sbuildin, 1) plugin_def("export_ps", "export sheets to ps/eps", sbuildin, 1) +plugin_def("export_spice", "export SPICE netlist", sbuildin, 1) plugin_def("export_svg", "export sheets to svg", sbuildin, 1) plugin_def("export_tedax", "export tEDAx netlist", sbuildin, 1) @@ -58,6 +59,7 @@ plugin_dep("io_altium", "lib_alien") plugin_dep("io_geda", "lib_alien") plugin_dep("io_ngrp_fawk", "lib_ngrp") +plugin_dep("io_ngrp_fawk", "script") plugin_dep("io_ngrp_tedax", "lib_ngrp") plugin_dep("io_tinycad", "lib_alien") plugin_dep("lib_alien", "query") Index: trunk/src/plugins/export_spice/Makefile =================================================================== --- trunk/src/plugins/export_spice/Makefile (nonexistent) +++ trunk/src/plugins/export_spice/Makefile (revision 7499) @@ -0,0 +1,2 @@ +all: + cd ../../sch-rnd && make mod_export_spice Index: trunk/src/plugins/export_spice/Plug.tmpasm =================================================================== --- trunk/src/plugins/export_spice/Plug.tmpasm (nonexistent) +++ trunk/src/plugins/export_spice/Plug.tmpasm (revision 7499) @@ -0,0 +1,10 @@ +put /local/rnd/mod {export_spice} +put /local/rnd/mod/OBJS [@ + $(PLUGDIR)/export_spice/export_spice.o +@] + +switch /local/module/export_spice/controls + case {buildin} include /local/csch/tmpasm/buildin; end; + case {plugin} include /local/csch/tmpasm/plugin; end; + case {disable} include /local/csch/tmpasm/disable; end; +end Index: trunk/src/plugins/export_spice/export_spice.c =================================================================== --- trunk/src/plugins/export_spice/export_spice.c (nonexistent) +++ trunk/src/plugins/export_spice/export_spice.c (revision 7499) @@ -0,0 +1,136 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - SPICE netlist export + * Copyright (C) 2023 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 Entrust in 2023) + * + * 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/sch-rnd + * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html + * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html + */ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static csch_plug_io_t espice_net; + +static int spice_export_prio(const char *fn, const char *fmt, csch_plug_io_type_t type) +{ + if (type != CSCH_IOTYP_NETLIST) + return 0; + if (rnd_strcasecmp(fmt, "spice") == 0) + return 100; + if (rnd_strcasecmp(fmt, "cir") == 0) + return 98; + if (rnd_strcasecmp(fmt, "net") == 0) + return 95; + return 0; +} + +static void spice_export_comps(FILE *f, csch_abstract_t *abs) +{ + htsp_entry_t *e, *p; + for(e = htsp_first(&abs->comps); e != NULL; e = htsp_next(&abs->comps, e)) { + csch_acomp_t *comp = e->value; + const char *refdes = "get_refdes(comp)"; + + if (refdes == NULL) + continue; + + for(p = htsp_first(&comp->ports); p != NULL; p = htsp_next(&comp->ports, p)) { + const csch_aport_t *port = p->value; +#if 0 + const char *pinnum = get_pinnum(port); + const char *pinname = get_alt_attr(&port->hdr.attr, "display/pinname", "name", NULL); +#endif + } + } +} + +static int spice_export_project_abst(const char *fn, const char *fmt, csch_abstract_t *abs) +{ + TODO("get hidlib as an arg") + rnd_design_t *hidlib = NULL; + FILE *f = rnd_fopen(hidlib, fn, "w"); + if (f == NULL) + return -1; + + fprintf(f, ".title sch-rnd export using export_spice\n"); + + spice_export_comps(f, abs); + + fprintf(f, ".end\n"); + + fclose(f); + return 0; +} + +#include "hid_impl.c" + +int pplg_check_ver_export_spice(int ver_needed) { return 0; } + +void pplg_uninit_export_spice(void) +{ + csch_plug_io_unregister(&espice_net); + rnd_export_remove_opts_by_cookie(spice_cookie); + rnd_hid_remove_hid(&spice_hid); +} + +int pplg_init_export_spice(void) +{ + RND_API_CHK_VER; + + espice_net.name = "export to SPICE netlist"; + espice_net.export_prio = spice_export_prio; + espice_net.export_project_abst = spice_export_project_abst; + espice_net.ext_export_project = ".cir"; + csch_plug_io_register(&espice_net); + + + rnd_hid_nogui_init(&spice_hid); + + spice_hid.struct_size = sizeof(rnd_hid_t); + spice_hid.name = "spice"; + spice_hid.description = "Exports project's SPICE netlist"; + spice_hid.exporter = 1; + + spice_hid.get_export_options = spice_get_export_options; + spice_hid.do_export = spice_do_export; + spice_hid.parse_arguments = spice_parse_arguments; + spice_hid.argument_array = spice_values; + + spice_hid.usage = spice_usage; + + rnd_hid_register_hid(&spice_hid); + rnd_hid_load_defaults(&spice_hid, spice_options, NUM_OPTIONS); + + + return 0; +} + Index: trunk/src/plugins/export_spice/export_spice.pup =================================================================== --- trunk/src/plugins/export_spice/export_spice.pup (nonexistent) +++ trunk/src/plugins/export_spice/export_spice.pup (revision 7499) @@ -0,0 +1,9 @@ +$class export +$short export SPICE netlist +$long SPICE netlist exporter for circuit simulation +$state WIP +$fmt-native no +$fmt-feature-e spice +$package (core) +default buildin +autoload 1 Index: trunk/src/plugins/export_spice/hid_impl.c =================================================================== --- trunk/src/plugins/export_spice/hid_impl.c (nonexistent) +++ trunk/src/plugins/export_spice/hid_impl.c (revision 7499) @@ -0,0 +1,101 @@ +/* + * COPYRIGHT + * + * cschem - modular/flexible schematics editor - SPICE netlist export + * Copyright (C) 2023 Tibor 'Igor2' Palinkas + * + * (Supported by NLnet NGI0 Entrust in 2023) + * + * 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/sch-rnd + * contact lead developer: http://www.repo.hu/projects/sch-rnd/contact.html + * mailing list: http://www.repo.hu/projects/sch-rnd/contact.html + */ + +#include +#include +#include +#include +#include +#include +#include + +static const char spice_cookie[] = "SPICE export hid"; + +static const rnd_export_opt_t spice_options[] = { + {"outfile", "Name of the SPICE netlist output file", + RND_HATT_STRING, 0, 0, {0, 0, 0}, 0}, +#define HA_outfile 0 + + {"view", "Name of the view to export (use first view when not specified)", + RND_HATT_STRING, 0, 0, {0, 0, 0}, 0}, +#define HA_view 1 +}; + +#define NUM_OPTIONS (sizeof(spice_options)/sizeof(spice_options[0])) + +static rnd_hid_attr_val_t spice_values[NUM_OPTIONS]; + +static const rnd_export_opt_t *spice_get_export_options(rnd_hid_t *hid, int *n, rnd_design_t *dsg, void *appspec) +{ + const char *val = spice_values[HA_outfile].str; + + if ((dsg != NULL) && ((val == NULL) || (*val == '\0'))) + csch_derive_default_filename(dsg, 1, &spice_values[HA_outfile], ".cir"); + + if (n) + *n = NUM_OPTIONS; + return spice_options; +} + +static void spice_do_export(rnd_hid_t *hid, rnd_design_t *design, rnd_hid_attr_val_t *options, void *appspec) +{ + csch_sheet_t *sheet = (csch_sheet_t *)design; + int viewid = CSCH_VIEW_DEFAULT; + + if (!options) { + spice_get_export_options(hid, 0, design, appspec); + options = spice_values; + } + + if ((options[HA_view].str != NULL) && (options[HA_view].str[0] != '\0')) { + viewid = csch_view_get_id((csch_project_t *)sheet->hidlib.project, options[HA_view].str); + if (viewid < 0) { + rnd_message(RND_MSG_ERROR, "No such view in the project: '%s'\n", options[HA_view].str); + return; + } + } + + sch_rnd_export_prj_abst((csch_project_t *)sheet->hidlib.project, sheet, viewid, "spice", options[HA_outfile].str); +} + +static int spice_usage(rnd_hid_t *hid, const char *topic) +{ + fprintf(stderr, "\nSPICE exporter command line arguments:\n\n"); + rnd_hid_usage(spice_options, sizeof(spice_options) / sizeof(spice_options[0])); + fprintf(stderr, "\nUsage: sch-rnd [generic_options] -x spice [options] foo.rs\n\n"); + return 0; +} + + +static int spice_parse_arguments(rnd_hid_t *hid, int *argc, char ***argv) +{ + rnd_export_register_opts2(hid, spice_options, sizeof(spice_options) / sizeof(spice_options[0]), spice_cookie, 0); + return rnd_hid_parse_command_line(argc, argv); +} + +rnd_hid_t spice_hid = {0}; Index: trunk/src/plugins/plugins_ALL.tmpasm =================================================================== --- trunk/src/plugins/plugins_ALL.tmpasm (revision 7498) +++ trunk/src/plugins/plugins_ALL.tmpasm (revision 7499) @@ -8,6 +8,7 @@ include {../src/plugins/export_lpr/Plug.tmpasm} include {../src/plugins/export_png/Plug.tmpasm} include {../src/plugins/export_ps/Plug.tmpasm} +include {../src/plugins/export_spice/Plug.tmpasm} include {../src/plugins/export_svg/Plug.tmpasm} include {../src/plugins/export_tedax/Plug.tmpasm} include {../src/plugins/gui/Plug.tmpasm}