Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 32325) +++ trunk/scconfig/Rev.h (revision 32326) @@ -1 +1 @@ -static const int myrev = 32317; +static const int myrev = 32326; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 32325) +++ trunk/scconfig/Rev.tab (revision 32326) @@ -1,4 +1,4 @@ -32317 configure new netlist import plugins: pads ascii netlist, orcad pcb II netlist, accel net +32326 configure new netlist import plugins: pads ascii netlist, orcad pcb II netlist, accel netliet, protel netlist 2.0 32284 configure io_tedax: file format support for autorouters 32216 configure cleanup: eahc plugin shall register its own menus 32187 configure librnd: infra for menu patching Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 32325) +++ trunk/scconfig/plugins.h (revision 32326) @@ -88,6 +88,7 @@ plugin_def("import_netlist", "import netlist", sbuildin, 1, 0) plugin_def("import_orcad_net", "import Orcad netlist", sbuildin, 1, 0) plugin_def("import_pads_net", "import PADS ascii netlist .asc", sbuildin, 1, 0) +plugin_def("import_protel_net","import Protel netlist 2.0", sbuildin, 1, 0) plugin_def("import_pxm_gd", "import pixmaps from png/gif/jpg", sbuildin, 1, 0) plugin_def("import_pxm_pnm", "import pixmaps from pnm ", sbuildin, 1, 0) plugin_def("import_sch2", "import sch v2", sbuildin, 1, 0) Index: trunk/src_plugins/import_protel_net/Makefile =================================================================== --- trunk/src_plugins/import_protel_net/Makefile (nonexistent) +++ trunk/src_plugins/import_protel_net/Makefile (revision 32326) @@ -0,0 +1,5 @@ +all: + cd ../../src && $(MAKE) mod_import_protel_net + +clean: + rm *.o *.so 2>/dev/null ; true Index: trunk/src_plugins/import_protel_net/Plug.tmpasm =================================================================== --- trunk/src_plugins/import_protel_net/Plug.tmpasm (nonexistent) +++ trunk/src_plugins/import_protel_net/Plug.tmpasm (revision 32326) @@ -0,0 +1,10 @@ +put /local/pcb/mod {import_protel_net} +put /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_protel_net/protel_net.o @] +put /local/pcb/mod/MENUFILE {protel_net-menu.lht} +put /local/pcb/mod/MENUVAR {protel_net_menu} + +switch /local/pcb/import_protel_net/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/import_protel_net/import_protel_net.pup =================================================================== --- trunk/src_plugins/import_protel_net/import_protel_net.pup (nonexistent) +++ trunk/src_plugins/import_protel_net/import_protel_net.pup (revision 32326) @@ -0,0 +1,9 @@ +$class import +$short import Protel netlist 2.0 +$long Import the netlist and footprints from a Protel netlist. +$state works +$fmt-native no +$fmt-feature-r import netlist and footprint info from Protel netlists 2.0 +$package import-net +default buildin +autoload 1 Index: trunk/src_plugins/import_protel_net/protel_net-menu.lht =================================================================== --- trunk/src_plugins/import_protel_net/protel_net-menu.lht (nonexistent) +++ trunk/src_plugins/import_protel_net/protel_net-menu.lht (revision 32326) @@ -0,0 +1,9 @@ +ha:rnd-menu-v1 { + li:anchored { + ha:@import_sch { + li:submenu { + ha:Load Protel netlist 2.0 file = { action=LoadProtelNetFrom() } + } + } + } +} Index: trunk/src_plugins/import_protel_net/protel_net.c =================================================================== --- trunk/src_plugins/import_protel_net/protel_net.c (nonexistent) +++ trunk/src_plugins/import_protel_net/protel_net.c (revision 32326) @@ -0,0 +1,212 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * sch import: Protel netlist 2.0 + * pcb-rnd Copyright (C) 2020 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/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" + +#include +#include +#include +#include + +#include "board.h" +#include "data.h" +#include "plug_import.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "menu_internal.c" + +static const char *protel_net_cookie = "protel_net importer"; + +/* remove leading whitespace */ +#define ltrim(s) while(isspace(*s)) s++ + +/* remove trailing newline */ +#define rtrim(s) \ + do { \ + char *end; \ + for(end = s + strlen(s) - 1; (end >= s) && ((*end == '\r') || (*end == '\n')); end--) \ + *end = '\0'; \ + } while(0) +static int protel_net_parse_net(FILE *fn) +{ + char line[1024], signal[1024]; + enum { NONE, NET, PART } mode = NONE; + + rnd_actionva(&PCB->hidlib, "ElementList", "start", NULL); + rnd_actionva(&PCB->hidlib, "Netlist", "Freeze", NULL); + rnd_actionva(&PCB->hidlib, "Netlist", "Clear", NULL); + + *signal = '\0'; + + while(fgets(line, sizeof(line), fn) != NULL) { + int argc; + char **argv, *s, *next, *pin; + + s = line; + ltrim(s); + rtrim(s); + +/* rnd_actionva(&PCB->hidlib, "ElementList", "Need", argv[0], argv[1], "", NULL);*/ +/* rnd_actionva(&PCB->hidlib, "Netlist", "Add", signal, s, NULL);*/ + } + } + + rnd_actionva(&PCB->hidlib, "Netlist", "Sort", NULL); + rnd_actionva(&PCB->hidlib, "Netlist", "Thaw", NULL); + rnd_actionva(&PCB->hidlib, "ElementList", "Done", NULL); + + return 0; +} + + +static int protel_net_load(const char *fname_net) +{ + FILE *fn; + int ret = 0; + + fn = rnd_fopen(&PCB->hidlib, fname_net, "r"); + if (fn == NULL) { + rnd_message(RND_MSG_ERROR, "can't open file '%s' for read\n", fname_net); + return -1; + } + + ret = protel_net_parse_net(fn); + + fclose(fn); + return ret; +} + +static const char pcb_acts_LoadProtelNetFrom[] = "LoadProtelNetFrom(filename)"; +static const char pcb_acth_LoadProtelNetFrom[] = "Loads the specified pads ascii netlist .asc file."; +fgw_error_t pcb_act_LoadProtelNetFrom(fgw_arg_t *res, int argc, fgw_arg_t *argv) +{ + const char *fname = NULL; + static char *default_file = NULL; + + RND_ACT_MAY_CONVARG(1, FGW_STR, LoadProtelNetFrom, fname = argv[1].val.str); + + if (!fname || !*fname) { + fname = rnd_gui->fileselect(rnd_gui, "Load pads ascii netlist file...", + "Picks a pads ascii netlist file to load.\n", + default_file, ".asc", NULL, "protel_net", RND_HID_FSD_READ, NULL); + if (fname == NULL) + return 1; + if (default_file != NULL) { + free(default_file); + default_file = NULL; + } + } + + RND_ACT_IRES(0); + return protel_net_load(fname); +} + +static int protel_net_support_prio(pcb_plug_import_t *ctx, unsigned int aspects, const char **args, int numargs) +{ + FILE *f; + unsigned int good = 0; + + if ((aspects != IMPORT_ASPECT_NETLIST) || (numargs != 1)) + return 0; /* only pure netlist import is supported from a single file*/ + + f = rnd_fopen(&PCB->hidlib, args[0], "r"); + if (f == NULL) + return 0; + + for(;;) { + char *s, line[1024]; + s = fgets(line, sizeof(line), f); + if (s == NULL) + break; + while(isspace(*s)) s++; + if (strncmp(s, "PROTEL NETLIST 2.0", 18) == 0) { + fclose(f); + return 100; + } + } + + fclose(f); + + return 0; +} + + +static int protel_net_import(pcb_plug_import_t *ctx, unsigned int aspects, const char **fns, int numfns) +{ + if (numfns != 1) { + rnd_message(RND_MSG_ERROR, "import_protel_net: requires exactly 1 input file name\n"); + return -1; + } + return protel_net_load(fns[0]); +} + +static pcb_plug_import_t import_protel_net; + +rnd_action_t protel_net_action_list[] = { + {"LoadProtelNetFrom", pcb_act_LoadProtelNetFrom, pcb_acth_LoadProtelNetFrom, pcb_acts_LoadProtelNetFrom} +}; + +int pplg_check_ver_import_protel_net(int ver_needed) { return 0; } + +void pplg_uninit_import_protel_net(void) +{ + rnd_remove_actions_by_cookie(protel_net_cookie); + RND_HOOK_UNREGISTER(pcb_plug_import_t, pcb_plug_import_chain, &import_protel_net); + rnd_hid_menu_unload(rnd_gui, protel_net_cookie); +} + +int pplg_init_import_protel_net(void) +{ + RND_API_CHK_VER; + + /* register the IO hook */ + import_protel_net.plugin_data = NULL; + + import_protel_net.fmt_support_prio = protel_net_support_prio; + import_protel_net.import = protel_net_import; + import_protel_net.name = "protel_net"; + import_protel_net.desc = "schamtics from protel netlist 2.0"; + import_protel_net.ui_prio = 50; + import_protel_net.single_arg = 1; + import_protel_net.all_filenames = 1; + import_protel_net.ext_exec = 0; + + RND_HOOK_REGISTER(pcb_plug_import_t, pcb_plug_import_chain, &import_protel_net); + + RND_REGISTER_ACTIONS(protel_net_action_list, protel_net_cookie) + rnd_hid_menu_load(rnd_gui, NULL, protel_net_cookie, 175, NULL, 0, protel_net_menu, "plugin: import protel_net"); + return 0; +} Index: trunk/src_plugins/plugins_ALL.tmpasm =================================================================== --- trunk/src_plugins/plugins_ALL.tmpasm (revision 32325) +++ trunk/src_plugins/plugins_ALL.tmpasm (revision 32326) @@ -66,6 +66,7 @@ include {../src_plugins/import_netlist/Plug.tmpasm} include {../src_plugins/import_orcad_net/Plug.tmpasm} include {../src_plugins/import_pads_net/Plug.tmpasm} +include {../src_plugins/import_protel_net/Plug.tmpasm} include {../src_plugins/import_pxm_gd/Plug.tmpasm} include {../src_plugins/import_pxm_pnm/Plug.tmpasm} include {../src_plugins/import_sch2/Plug.tmpasm}