Index: Makefile =================================================================== --- Makefile (nonexistent) +++ Makefile (revision 13364) @@ -0,0 +1,5 @@ +all: + cd ../../src && $(MAKE) mod_extedit + +clean: + rm *.o *.so 2>/dev/null ; true Index: Plug.tmpasm =================================================================== --- Plug.tmpasm (nonexistent) +++ Plug.tmpasm (revision 13364) @@ -0,0 +1,10 @@ +put /local/pcb/mod {extedit} +put /local/pcb/mod/OBJS [@ + $(PLUGDIR)/extedit/extedit.o +@] + +switch /local/pcb/extedit/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: extedit.c =================================================================== --- extedit.c (nonexistent) +++ extedit.c (revision 13364) @@ -0,0 +1,184 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2017 Tibor 'Igor2' Palinkas + * + * This module, dialogs, was written and is Copyright (C) 2017 by Tibor Palinkas + * this module is also subject to the GNU GPL as described below + * + * 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. + * + */ + +#include "config.h" + +#include "hid.h" +#include "hid_attrib.h" +#include "hid_actions.h" +#include "hid_dad.h" +#include "action_helper.h" + +#include "board.h" +#include "compat_fs.h" +#include "const.h" +#include "conf_core.h" +#include "data.h" +#include "buffer.h" +#include "safe_fs.h" +#include "search.h" +#include "../src_plugins/io_lihata/io_lihata.h" +#include "../src_plugins/io_lihata/write.h" +#include "../src_plugins/io_lihata/read.h" + +typedef enum { + EEF_LIHATA +} extedit_fmt_t; + +typedef struct extedit_method_s { + char *name; + long types; + extedit_fmt_t fmt; + char *command; +} extedit_method_t; + +static extedit_method_t methods[] = { + {"pcb-rnd", PCB_TYPE_SUBC | PCB_TYPE_ELEMENT, EEF_LIHATA, "pcb-rnd %f"}, + {"text editor", PCB_TYPE_SUBC | PCB_TYPE_ELEMENT, EEF_LIHATA, "editor %f"}, + {NULL, 0, 0, NULL} +}; + +/* DAD-based interactive method editor */ +static extedit_method_t *extedit_interactive(void) +{ +#warning TODO + return NULL; +} + +static const char pcb_acts_extedit[] = "extedit(object|selected, [interactive|method])\n"; +static const char pcb_acth_extedit[] = "Invoke an external program to edit a specific part of the current board."; +static int pcb_act_extedit(int argc, const char **argv, pcb_coord_t x, pcb_coord_t y) +{ + long type; + void *ptr1, *ptr2, *ptr3; + extedit_method_t *mth = NULL; + char *tmp_fn; + int ret = 1; + FILE *f; + + /* pick up the object to edit */ + if ((argc == 0) || (pcb_strcasecmp(argv[0], "object") == 0)) { + pcb_gui->get_coords("Click on object to edit", &x, &y); + type = pcb_search_screen(x, y, 0xFFFFFFFF, &ptr1, &ptr2, &ptr3); + } + else if ((argc > 0) && (pcb_strcasecmp(argv[0], "selected") == 0)) { +#warning TODO + pcb_message(PCB_MSG_ERROR, "\"Selected\" not supported yet\n"); + return 1; + } + else { + pcb_message(PCB_MSG_ERROR, "Wrong 1st argument '%s'\n", argv[0]); + return 1; + } + + /* determine the method */ + if (argc > 1) { + for(mth = methods; mth->name != NULL; mth++) { + if (pcb_strcasecmp(mth->name, argv[1]) == 0) + break; + } + if (mth == NULL) { + pcb_message(PCB_MSG_ERROR, "unknown method '%s'; available methods:\n", argv[1]); + for(mth = methods; mth->name != NULL; mth++) + pcb_message(PCB_MSG_ERROR, "%s ", mth->name); + pcb_message(PCB_MSG_ERROR, "\n"); + return 1; + } + } + if (mth == NULL) { + mth = extedit_interactive(); + if (mth == NULL) /* no method selected */ + return 1; + } + + tmp_fn = pcb_tempfile_name_new("extedit"); + if (tmp_fn == NULL) { + pcb_message(PCB_MSG_ERROR, "Failed to create temporary file\n"); + return 1; + } + + /* export */ + switch(mth->fmt) { + case EEF_LIHATA: + { + int bn =PCB_MAX_BUFFER - 1; + + pcb_buffer_set_number(bn); + pcb_buffer_clear(PCB, PCB_PASTEBUFFER); + if (pcb_copy_obj_to_buffer(PCB, pcb_buffers[bn].Data, PCB->Data, type, ptr1, ptr2, ptr3) == NULL) { + pcb_message(PCB_MSG_ERROR, "Failed to copy target objects to temporary paste buffer\n"); + goto quit1; + } + + f = pcb_fopen(tmp_fn, "w"); + if (f == NULL) { + pcb_message(PCB_MSG_ERROR, "Failed to open temporary file\n"); + goto quit1; + } + + if (io_lihata_write_element(&plug_io_lihata_v4, f, pcb_buffers[bn].Data) != 0) { + fclose(f); + pcb_message(PCB_MSG_ERROR, "Failed to export target objects to lihata footprint.\n"); + goto quit1; + } + fclose(f); + printf("tmp=%s\n", tmp_fn); + } + break; + } + + /* invoke external program */ +#warning TODO + + /* load the result */ +#warning TODO + + quit1:; +/* pcb_tempfile_unlink(tmp_fn);*/ + return ret; +} + +static pcb_hid_action_t extedit_action_list[] = { + {"extedit", 0, pcb_act_extedit, + pcb_acts_extedit, pcb_acth_extedit} +}; + +static const char *extedit_cookie = "extedit plugin"; + +PCB_REGISTER_ACTIONS(extedit_action_list, extedit_cookie) + +int pplg_check_ver_extedit(int ver_needed) { return 0; } + +void pplg_uninit_extedit(void) +{ + pcb_hid_remove_actions_by_cookie(extedit_cookie); +} + +#include "dolists.h" +int pplg_init_extedit(void) +{ + PCB_REGISTER_ACTIONS(extedit_action_list, extedit_cookie) + return 0; +} Index: extedit.pup =================================================================== --- extedit.pup (nonexistent) +++ extedit.pup (revision 13364) @@ -0,0 +1,7 @@ +$class feature +$short edit with external program +$long invoke external program to edit parts of the current board +$state works +dep io_lihata +default buildin +autoload 1