Index: Makefile =================================================================== --- Makefile (nonexistent) +++ Makefile (revision 32306) @@ -0,0 +1,5 @@ +all: + cd ../../src && $(MAKE) mod_import_orcad_net + +clean: + rm *.o *.so 2>/dev/null ; true Index: Plug.tmpasm =================================================================== --- Plug.tmpasm (nonexistent) +++ Plug.tmpasm (revision 32306) @@ -0,0 +1,10 @@ +put /local/pcb/mod {import_orcad_net} +put /local/pcb/mod/OBJS [@ $(PLUGDIR)/import_orcad_net/orcad_net.o @] +put /local/pcb/mod/MENUFILE {orcad_net-menu.lht} +put /local/pcb/mod/MENUVAR {orcad_net_menu} + +switch /local/pcb/import_orcad_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: import_orcad_net.pup =================================================================== --- import_orcad_net.pup (nonexistent) +++ import_orcad_net.pup (revision 32306) @@ -0,0 +1,9 @@ +$class import +$short import Orcad netlist +$long Import the netlist and footprints from a Orcad netlist. +$state works +$fmt-native no +$fmt-feature-r import netlist and footprint info from Orcad PCB II netlists +$package import-net +default buildin +autoload 1 Index: menu_internal.c =================================================================== --- menu_internal.c (nonexistent) +++ menu_internal.c (revision 32306) @@ -0,0 +1,21 @@ +/* Autogenerated by cquote.c - DO NOT EDIT */ +/* (Using character array instead of string literal for long strings) */ +const char orcad_net_menu_arr[] = { + 'h','a',':','r','n','d','-','m','e','n','u','-','v','1',' ','{', + '\n', + '\t','l','i',':','a','n','c','h','o','r','e','d',' ','{','\n', + '\t','\t','h','a',':','@','i','m','p','o','r','t','_','s','c', + 'h',' ','{','\n', + '\t','\t','\t','l','i',':','s','u','b','m','e','n','u',' ','{', + '\n', + '\t','\t','\t','\t','h','a',':','L','o','a','d',' ','P','A','D', + 'S',' ','A','S','C','I','I',' ','.','a','s','c',' ','f','i','l', + 'e',' ','=',' ','{',' ','a','c','t','i','o','n','=','L','o','a', + 'd','P','a','d','s','N','e','t','F','r','o','m','(',')',' ','}', + '\n', + '\t','\t','\t','}','\n', + '\t','\t','}','\n', + '\t','}','\n', + '}','\n', + 0}; +const char *orcad_net_menu = orcad_net_menu_arr; Index: orcad_net-menu.lht =================================================================== --- orcad_net-menu.lht (nonexistent) +++ orcad_net-menu.lht (revision 32306) @@ -0,0 +1,9 @@ +ha:rnd-menu-v1 { + li:anchored { + ha:@import_sch { + li:submenu { + ha:Load Orcad PCB II netlist file = { action=LoadOrcadNetFrom() } + } + } + } +} Index: orcad_net.c =================================================================== --- orcad_net.c (nonexistent) +++ orcad_net.c (revision 32306) @@ -0,0 +1,193 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * sch import: PADS netlist ASCII (powerpcb?) + * 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 "board.h" +#include "data.h" +#include "plug_import.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "menu_internal.c" + +static const char *orcad_net_cookie = "orcad_net importer"; + +static int orcad_net_parse_net(FILE *fn) +{ + + rnd_actionva(&PCB->hidlib, "ElementList", "start", NULL); + rnd_actionva(&PCB->hidlib, "Netlist", "Freeze", NULL); + rnd_actionva(&PCB->hidlib, "Netlist", "Clear", NULL); + +/* 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 orcad_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 = orcad_net_parse_net(fn); + + fclose(fn); + return ret; +} + +static const char pcb_acts_LoadOrcadNetFrom[] = "LoadOrcadNetFrom(filename)"; +static const char pcb_acth_LoadOrcadNetFrom[] = "Loads the specified pads ascii netlist .asc file."; +fgw_error_t pcb_act_LoadOrcadNetFrom(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, LoadOrcadNetFrom, 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, "orcad_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 orcad_net_load(fname); +} + +static int orcad_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, "!PADS-", 6) == 0) + good |= 1; + else if (strncmp(s, "*PART*", 6) == 0) + good |= 2; + else if (strncmp(s, "*NET*", 5) == 0) + good |= 4; + if (good == (1|2|4)) { + fclose(f); + return 100; + } + } + + fclose(f); + + return 0; +} + + +static int orcad_net_import(pcb_plug_import_t *ctx, unsigned int aspects, const char **fns, int numfns) +{ + if (numfns != 1) { + rnd_message(RND_MSG_ERROR, "import_orcad_net: requires exactly 1 input file name\n"); + return -1; + } + return orcad_net_load(fns[0]); +} + +static pcb_plug_import_t import_orcad_net; + +rnd_action_t orcad_net_action_list[] = { + {"LoadOrcadNetFrom", pcb_act_LoadOrcadNetFrom, pcb_acth_LoadOrcadNetFrom, pcb_acts_LoadOrcadNetFrom} +}; + +int pplg_check_ver_import_orcad_net(int ver_needed) { return 0; } + +void pplg_uninit_import_orcad_net(void) +{ + rnd_remove_actions_by_cookie(orcad_net_cookie); + RND_HOOK_UNREGISTER(pcb_plug_import_t, pcb_plug_import_chain, &import_orcad_net); + rnd_hid_menu_unload(rnd_gui, orcad_net_cookie); +} + +int pplg_init_import_orcad_net(void) +{ + RND_API_CHK_VER; + + /* register the IO hook */ + import_orcad_net.plugin_data = NULL; + + import_orcad_net.fmt_support_prio = orcad_net_support_prio; + import_orcad_net.import = orcad_net_import; + import_orcad_net.name = "orcad_net"; + import_orcad_net.desc = "schamtics from pads ascii netlist"; + import_orcad_net.ui_prio = 50; + import_orcad_net.single_arg = 1; + import_orcad_net.all_filenames = 1; + import_orcad_net.ext_exec = 0; + + RND_HOOK_REGISTER(pcb_plug_import_t, pcb_plug_import_chain, &import_orcad_net); + + RND_REGISTER_ACTIONS(orcad_net_action_list, orcad_net_cookie) + rnd_hid_menu_load(rnd_gui, NULL, orcad_net_cookie, 175, NULL, 0, orcad_net_menu, "plugin: import orcad_net"); + return 0; +}