Index: trunk/src_plugins/ar_extern/ar_extern.c =================================================================== --- trunk/src_plugins/ar_extern/ar_extern.c (revision 32348) +++ trunk/src_plugins/ar_extern/ar_extern.c (revision 32349) @@ -37,6 +37,7 @@ #include #include #include +#include #include "conf_core.h" #include "obj_pstk_inlines.h" #include "src_plugins/lib_compat_help/pstk_compat.h" @@ -44,15 +45,71 @@ static const char *extern_cookie = "extern autorouter plugin"; +typedef enum { + ERSC_BOARD, ERSC_SELECTED +} ext_route_scope_t; +typedef struct { + const char *name; + int (*route)(pcb_board_t *pcb, ext_route_scope_t scope, const char *method, int argc, fgw_arg_t *argv); +} ext_router_t; + +#include "e_route-rnd.c" + +static const ext_router_t *routers[] = { &route_rnd, NULL }; + +static const ext_router_t *find_router(const char *name) +{ + const ext_router_t **r; + + for(r = routers; *r != NULL; r++) + if (strcmp((*r)->name, name) == 0) + return *r; + + return NULL; +} + static const char pcb_acts_extroute[] = "extroute(board|selected, router, [confkey=value, ...])"; static const char pcb_acth_extroute[] = "Executed external autorouter to route the board or parts of the board"; fgw_error_t pcb_act_extroute(fgw_arg_t *res, int argc, fgw_arg_t *argv) { - const char *scope, *router; + const char *scope, *router_; + char *router, *method; + ext_route_scope_t scp; + const ext_router_t *r; + pcb_board_t *pcb = PCB_ACT_BOARD; + + RND_ACT_CONVARG(1, FGW_STR, extroute, scope = argv[1].val.str); - RND_ACT_CONVARG(2, FGW_STR, extroute, scope = argv[2].val.str); + RND_ACT_CONVARG(2, FGW_STR, extroute, router_ = argv[2].val.str); + + if (strcmp(scope, "board") == 0) scp = ERSC_BOARD; + else if (strcmp(scope, "selected") == 0) scp = ERSC_SELECTED; + else { + rnd_message(RND_MSG_ERROR, "Invalid scope: '%s'\n", scope); + return FGW_ERR_ARG_CONV; + } + router = rnd_strdup(router_); + method = strchr(router, '/'); + if (method != NULL) { + *method = '\0'; + method++; + if (*method == '\0') + method = NULL; + } + + r = find_router(router); + if (r == NULL) { + free(router); + rnd_message(RND_MSG_ERROR, "Invalid router: '%s'\n", scope); + return FGW_ERR_ARG_CONV; + } + + if (r->route != NULL) + RND_ACT_IRES(r->route(pcb, scp, method, argc-3, argv+3)); + + free(router); return 0; } Index: trunk/src_plugins/ar_extern/e_route-rnd.c =================================================================== --- trunk/src_plugins/ar_extern/e_route-rnd.c (nonexistent) +++ trunk/src_plugins/ar_extern/e_route-rnd.c (revision 32349) @@ -0,0 +1,38 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * + * auto routing with external router process + * 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") + */ + +static int rtrnd_route(pcb_board_t *pcb, ext_route_scope_t scope, const char *method, int argc, fgw_arg_t *argv) +{ + rnd_trace("woo\n"); + return 0; +} + +static const ext_router_t route_rnd = { + "route-rnd", + rtrnd_route +};