Index: scconfig/hooks.c =================================================================== --- scconfig/hooks.c (revision 1067) +++ scconfig/hooks.c (revision 1068) @@ -278,16 +278,16 @@ const char *gcfg = get("libs/script/gpmi/gpmi-config"); int generr = 0; - printf("Generating pcb-gpmi/Makefile.conf (%d)\n", generr |= tmpasm("../src/pcb-gpmi", "Makefile.config.in", "Makefile.config")); + printf("Generating pcb-gpmi/Makefile.conf (%d)\n", generr |= tmpasm("../src_plugins/gpmi/pcb-gpmi", "Makefile.config.in", "Makefile.config")); printf("Configuring gpmi packages...\n"); - tmp = str_concat("", "cd ../src/pcb-gpmi/gpmi_plugin/gpmi_pkg && ", gcfg, " --pkggrp && ./configure", NULL); + tmp = str_concat("", "cd ../src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg && ", gcfg, " --pkggrp && ./configure", NULL); generr |= system(tmp); free(tmp); printf("Configuring gpmi plugin \"app\"\n"); - tmp = str_concat("", "cd ../src/pcb-gpmi/gpmi_plugin && ", gcfg, " --app", NULL); + tmp = str_concat("", "cd ../src_plugins/gpmi//pcb-gpmi/gpmi_plugin && ", gcfg, " --app", NULL); generr |= system(tmp); free(tmp); Index: src/pcb-gpmi/Makefile.config.in =================================================================== --- src/pcb-gpmi/Makefile.config.in (revision 1067) +++ src/pcb-gpmi/Makefile.config.in (nonexistent) @@ -1,15 +0,0 @@ -print [@ -### Generated by scconfig, do not edit ### - -###TODO1### -PCB_SRC=$(PCB_GPMI_ROOT)/../.. - -PCB_CFLAGS= \ - @/local/global_cflags@ \ - @/target/libs/sul/glib/cflags@ \ - @/target/libs/script/gpmi/cflags@ - - -PCB_LDFLAGS= @/target/libs/script/gpmi/ldflags@ - -@] Index: src/pcb-gpmi/gpmi_plugin/gpmi_plugin.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_plugin.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_plugin.h (nonexistent) @@ -1,3 +0,0 @@ -extern int gpmi_hid_gui_inited; /* whether the gui is already initialzied */ -void gpmi_hid_print_error(gpmi_err_stack_t *entry, char *string); - Index: src/pcb-gpmi/gpmi_plugin/manage_scripts.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/manage_scripts.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/manage_scripts.c (nonexistent) @@ -1,241 +0,0 @@ -#include -#include -#include -#include -#include -#include "src/misc.h" -#include "src/event.h" -#include "gpmi_plugin.h" -#include "scripts.h" - -extern HID *gui; - -#define attr_make_label(attr, name_, help_) \ -do { \ - memset((attr), 0, sizeof(HID_Attribute)); \ - (attr)->name = name_; \ - (attr)->help_text = help_; \ - (attr)->type = HID_Label; \ -} while(0) - -#define attr_make_label_str(attr, name1, name2, help_) \ -do { \ - char *__names__; \ - __names__ = Concat(name1, name2, NULL); \ - attr_make_label(attr, __names__, help_); \ -} while(0) - - -#define attr_make_enum(attr, name_, help_, enum_vals, default_item) \ -do { \ - memset((attr), 0, sizeof(HID_Attribute)); \ - (attr)->name = name_; \ - (attr)->help_text = help_; \ - (attr)->type = HID_Enum; \ - (attr)->enumerations = enum_vals; \ - (attr)->default_val.int_value = default_item; \ -} while(0) - -static hid_gpmi_script_info_t *choose_script(const char **operations, int *operation) -{ - HID_Attribute attr[3]; - HID_Attr_Val result[3]; - char **scrl, **s; - hid_gpmi_script_info_t *i; - int n, res; - - n = gpmi_hid_scripts_count(); - - scrl = malloc(sizeof(char *) * (n+1)); - for(i = hid_gpmi_script_info, n = 0; i != NULL; i = i->next, n++) { - char *basename; - - basename = strrchr(i->name, PCB_DIR_SEPARATOR_C); - if (basename == NULL) - basename = i->name; - else - basename++; - - scrl[n] = Concat(basename, "\t", i->module_name, NULL); - } - scrl[n] = NULL; - - attr_make_enum(&attr[0], "script", "Select an item from the list of scripts loaded", (const char **)scrl, -1); - - if (operations != NULL) - attr_make_enum(&attr[1], "operation", "Choose what to do with the script", operations, *operation); - - res = gui->attribute_dialog(attr, 1 + (operations != NULL), result, "GPMI manage scripts - select script", "Select one of the scripts already loaded"); - - /* free scrl slots before return */ - for(s = scrl; *s != NULL; s++) - free(*s); - - if (res) { - if (operation != NULL) - *operation = -1; - return NULL; - } - - if ((operations != NULL) && (operation != NULL)) - *operation = result[1].int_value; - -/* printf("res=%d\n", result[0].int_value);*/ - - if (result[0].int_value != -1) { - for(i = hid_gpmi_script_info, n = result[0].int_value; i != NULL && n != 0; i = i->next, n--); -/* printf("name=%s\n", i->name);*/ - return i; - } - return NULL; -} - -static hid_gpmi_script_info_t *load_script(void) -{ - char *fn, *ext; - hid_gpmi_script_info_t *info; - int default_mod = -1; - HID_Attribute attr[3]; - HID_Attr_Val result[3]; - char *exts[] = { - ".tcl", "tcl", - ".lua", "lua", - ".awk", "mawk", - ".mawk", "mawk", - ".py", "python", - ".scm", "scheme", - ".rb", "mruby", - ".ruby", "mruby", - ".st", "stutter", - ".pas", "ghli", - ".pl", "perl", - ".php", "php", - ".sh", "cli", - ".bash", "cli", - NULL, NULL - }; - const char *modules[] = { "tcl", "lua", "mawk", "python","scheme", "mruby", - "stutter", "ghli", "perl", "php", "cli", NULL }; - - - fn = gui->fileselect("Load script", "Load a GPMI script", NULL, NULL, "gpmi_load_script", HID_FILESELECT_READ); - - if (fn == NULL) - return NULL; - - ext = strrchr(fn, '.'); - if (ext != NULL) { - char **s; - const char **i; - /* find the extension in the extension->module pairs */ - for(s = exts; s[0] != NULL; s+=2) - if (strcmp(ext, s[0]) == 0) - break; - - /* if found, look up the "default enum value" for that module */ - if (s[1] != NULL) { - int n; - for(i = modules, n = 0; *i != NULL; i++,n++) { - if (strcmp(*i, s[1]) == 0) { - default_mod = n; - break; - } - } - } - } - - attr_make_enum(&attr[0], "module", "Select a GPMI module to interpret the script", modules, default_mod); - - if (gui->attribute_dialog(attr, 1, result, "GPMI manage scripts - select module", "Select one of GPMI modules to interpret the script")) - return NULL; - - if (result[0].int_value < 0) - return NULL; - - info = hid_gpmi_load_module(NULL, modules[result[0].int_value], fn, NULL); - if (info == NULL) - gui->report_dialog("GPMI script load", "Error loading the script.\nPlease consult the message log for details."); - return info; -} - -static void script_details(hid_gpmi_script_info_t *i) -{ - HID_Attribute attr[4]; - HID_Attr_Val result[4]; - char *cf; - - cf = i->conffile_name == NULL ? "" : i->conffile_name; - - - attr_make_label_str(&attr[0], "File name: ", i->name, "File name of the script (if not absolute, it's relative to the config file)"); - attr_make_label_str(&attr[1], "GPMI module: ", i->module_name, "Name of the GPMI module that is interpreting the script"); - attr_make_label_str(&attr[2], "Config file: ", cf, "Name of config file that requested the script to be loaded "); - gui->attribute_dialog(attr, 3, result, "GPMI manage scripts - script details", "Displaying detailed info on a script already loaded"); - free(attr[0].name); - free(attr[1].name); - free(attr[2].name); -} - -void gpmi_hid_manage_scripts(void) -{ - hid_gpmi_script_info_t *i; - static const char *err_no_script = "Error: you didn't select a script"; -#define CONSULT "Please consult the message log for details." - - const char *operations[] = {"show details...", "reload", "unload", "unload and remove from the config file", "load a new script...", "load a new script and add it in the config...", NULL}; - int op = 0; - i = choose_script(operations, &op); - switch(op) { - case 0: - if (i != NULL) - script_details(i); - else - gui->report_dialog("GPMI script details", err_no_script); - break; - case 1: - if (i != NULL) { - i = hid_gpmi_reload_module(i); - if (i == NULL) - gui->report_dialog("GPMI script reload", "Error reloading the script.\nThe script is now unloaded.\n" CONSULT "\n(e.g. there may be syntax errors in the script source)."); - } - else - gui->report_dialog("GPMI script reload", err_no_script); - break; - case 2: - if (i != NULL) { - if (gpmi_hid_script_unload(i) != 0) - gui->report_dialog("GPMI script unload", "Error unloading the script.\n" CONSULT "\n"); - } - else - gui->report_dialog("GPMI script unload", err_no_script); - break; - case 3: - if (i != NULL) { - int r1, r2; - r1 = gpmi_hid_script_remove(i); - r2 = gpmi_hid_script_unload(i); - if (r1 || r2) { - char *msg; - msg = Concat("Error:", - (r1 ? "couldnt't remove the script from the config file;" : ""), - (r2 ? "couldnt't unload the script;" : ""), - "\n" CONSULT "\n", NULL); - gui->report_dialog("GPMI script unload and remove", msg); - free(msg); - } - else - gui->report_dialog("GPMI script unload and remove", err_no_script); - } - break; - case 4: - load_script(); - break; - case 5: - i = load_script(); - if (i != NULL) { - if (gpmi_hid_script_addcfg(i) != 0) - gui->report_dialog("GPMI script add to config", "Error adding the script in user configuration.\n" CONSULT "\n"); - } - break; - } -} Index: src/pcb-gpmi/gpmi_plugin/manage_scripts.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/manage_scripts.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/manage_scripts.h (nonexistent) @@ -1 +0,0 @@ -void gpmi_hid_manage_scripts(void); Index: src/pcb-gpmi/gpmi_plugin/scripts.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/scripts.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/scripts.c (nonexistent) @@ -1,366 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include "src/misc.h" -#include "src/event.h" -#include "src/error.h" -#include "gpmi_plugin.h" -#include "scripts.h" - -#define CONFNAME "pcb-rnd-gpmi.conf" - -hid_gpmi_script_info_t *hid_gpmi_script_info = NULL; - -int gpmi_hid_scripts_count() -{ - int n; - hid_gpmi_script_info_t *i; - - for(i = hid_gpmi_script_info, n = 0; i != NULL; i = i->next, n++) ; - - return n; -} - -static void hid_gpmi_script_info_free(hid_gpmi_script_info_t *i) -{ - int ev; - char *ev_args; - ev = gpmi_event_find("ACTE_unload", &ev_args); - if (ev >= 0) - gpmi_event(i->module, ev, i->conffile_name); - - gpmi_mod_unload(i->module); - free(i->name); - free(i->module_name); - free(i->conffile_name); -} - -static hid_gpmi_script_info_t *hid_gpmi_script_info_add(hid_gpmi_script_info_t *i, gpmi_module *module, const char *name_, const char *module_name_, const char *conffile_name_) -{ - char *name, *module_name, *conffile_name; - /* make these copies before the free()'s because of reload calling us with - the same pointers... */ - name = strdup(name_); - module_name = strdup(module_name_); - if (conffile_name_ != NULL) - conffile_name = strdup(conffile_name_); - else - conffile_name = NULL; - - if (i == NULL) { - i = malloc(sizeof(hid_gpmi_script_info_t)); - i->next = hid_gpmi_script_info; - hid_gpmi_script_info = i; - } - else - hid_gpmi_script_info_free(i); - - i->module = module; - i->name = name; - i->module_name = module_name; - i->conffile_name = conffile_name; - return i; -} - -hid_gpmi_script_info_t *hid_gpmi_lookup(const char *name) -{ - hid_gpmi_script_info_t *i; - if (name == NULL) - return NULL; - for(i = hid_gpmi_script_info; i != NULL; i = i->next) - if (strcmp(name, i->name) == 0) - return i; - return NULL; -} - -/* Unload a script and remove it from the list */ -static void hid_gpmi_script_info_del(hid_gpmi_script_info_t *inf) -{ - hid_gpmi_script_info_t *i, *prev; - prev = NULL; - for(i = hid_gpmi_script_info; i != NULL; prev = i, i = i->next) { - if (i == inf) { - /* unlink */ - if (prev == NULL) - hid_gpmi_script_info = inf->next; - else - prev->next = inf->next; - hid_gpmi_script_info_free(inf); - free(inf); - return; - } - } -} - -static const char *conf_dir = NULL; - -hid_gpmi_script_info_t *hid_gpmi_load_module(hid_gpmi_script_info_t *i, const char *module_name, const char *params, const char *config_file_name) -{ - gpmi_module *module; - - Message("Loading GPMI module %s with params %s...\n", module_name, params); - module = gpmi_mod_load(module_name, params); - if (module == NULL) { - Message(" Failed loading the script. Details:\n"); - gpmi_err_stack_process_str(gpmi_hid_print_error); - } - gpmi_err_stack_destroy(NULL); - - if (module != NULL) { - hid_gpmi_script_info_t *ri; - int ev; - - ri = hid_gpmi_script_info_add(i, module, params, module_name, config_file_name); - if ((ri != NULL) && (gpmi_hid_gui_inited)) { - char *ev_args; - /* If a script is loaded with a GUI already inited, send the event right after the load */ - ev = gpmi_event_find("ACTE_gui_init", &ev_args); - gpmi_event(ri->module, ev, 0, NULL); - } - return ri; - } - - return NULL; -} - -hid_gpmi_script_info_t *hid_gpmi_reload_module(hid_gpmi_script_info_t *i) -{ - hid_gpmi_script_info_t *r; - const char *old_cd; - - old_cd = conf_dir; - - if (i->conffile_name != NULL) { - char *end; - conf_dir = strdup(i->conffile_name); - end = strrchr(conf_dir, PCB_DIR_SEPARATOR_C); - if (end == NULL) { - free((char *)conf_dir); - conf_dir = NULL; - } - else - *end = '\0'; - } - else - conf_dir = NULL; - - r = hid_gpmi_load_module(i, i->module_name, i->name, i->conffile_name); - - if (conf_dir != NULL) - free((char *)conf_dir); - conf_dir = old_cd; - - return r; -} - -/* Read and parse gpmi config file fin; - if fout is NULL, take cfn as config name and load all modules, return number of modules loaded; - else write all lines to fout, but comment out the one whose second token matches cfn, return number of commented lines - -*/ - -static int cfgfile(FILE *fin, FILE *fout, char *cfn) -{ -char line[1024], *module, *params, *s; - int found = 0; - - while(!(feof(fin))) { - *line = '\0'; - fgets(line, sizeof(line), fin); - switch(*line) { - case '\0': - case '\n': - case '\r': - case '#': - /* Empty line or comment */ - if (fout != NULL) - fprintf(fout, "%s", line); - break; - default: - module = strdup(line); - params = module + strcspn(module, "\t "); - while((*params == ' ') || (*params == '\t')) { - *(params) = '\0'; - params++; - } - s = strchr(params, '\n'); - *s = '\0'; - if (fout == NULL) { - fprintf(stderr, " ...loading %s %s\n", module, params); - hid_gpmi_load_module(NULL, module, params, cfn); - found++; - } - else { - if (strcmp(params, cfn) == 0) { - fprintf(fout, "# removed from pcb-rnd GUI: "); - found++; - } - if (fout != NULL) - fprintf(fout, "%s", line); - } - free(module); - } - } - - return found; -} - -void hid_gpmi_load_dir(const char *dir, int add_pkg_path) -{ - FILE *f; - char *cfn; - - conf_dir = dir; - cfn = Concat(dir, PCB_DIR_SEPARATOR_S, CONFNAME, NULL); -#ifdef CONFIG_DEBUG - fprintf(stderr, "pcb-gpmi: opening config: %s\n", cfn); -#endif - f = fopen(cfn, "r"); - if (f == NULL) { - free(cfn); -#ifdef CONFIG_DEBUG - fprintf(stderr, " ...failed\n"); -#endif - return; - } - - if (add_pkg_path) - gpmi_path_insert(GPMI_PATH_PACKAGES, dir); - - cfgfile(f, NULL, cfn); - - fclose(f); - free(cfn); - conf_dir = NULL; -} - -/* Dummy script name generator allows loading from any path */ -char *gpmi_hid_asm_scriptname(const void *info, const char *file_name) -{ - char buffer[1024]; - const char *cd; - - switch(*file_name) { - case '~': - file_name += 2; - if (homedir != NULL) { - snprintf(buffer, sizeof(buffer), "%s%c%s", homedir, PCB_DIR_SEPARATOR_C, file_name); - fprintf(stderr, "asm_scriptname FN=%s\n", buffer); - return strdup(buffer); - } - else { - fprintf(stderr, "pcb-gpmi error: can't access $HOME for substituting ~\n"); -#ifdef CONFIG_DEBUG - printf("FN=%s\n", file_name); -#endif - return strdup(file_name); - } - case PCB_DIR_SEPARATOR_C: /* full path */ - return strdup(file_name); - default: /* relative path - must be relative to the current conf_dir */ - if ((file_name[0] == '.') && (file_name[1] == PCB_DIR_SEPARATOR_C)) - file_name += 2; - if (conf_dir == NULL) - cd = "."; - else - cd = conf_dir; - snprintf(buffer, sizeof(buffer), "%s%c%s", cd, PCB_DIR_SEPARATOR_C, file_name); -#ifdef CONFIG_DEBUG - printf("FN=%s\n", buffer); -#endif - return strdup(buffer); - } - return NULL; -} - -int gpmi_hid_script_unload(hid_gpmi_script_info_t *i) -{ - hid_gpmi_script_info_del(i); - return 0; -} - -int gpmi_hid_script_remove(hid_gpmi_script_info_t *i) -{ - FILE *fin, *fout; - char *tmpfn; - int res; - - if (i->conffile_name == NULL) { - Message("gpmi_hid_script_remove(): can't remove script from configs, the script is not loaded from a config.\n"); - return -1; - } - - fin = fopen(i->conffile_name, "r"); - if (fin == NULL) { - Message("gpmi_hid_script_remove(): can't remove script from configs, can't open %s for read.\n", i->conffile_name); - return -1; - } - tmpfn = Concat(i->conffile_name, ".tmp", NULL); - fout = fopen(tmpfn, "w"); - if (fout == NULL) { - Message("gpmi_hid_script_remove(): can't remove script from configs, can't create %s.\n", tmpfn); - fclose(fin); - free(tmpfn); - return -1; - } - - res = cfgfile(fin, fout, i->name); - - fclose(fin); - fclose(fout); - - if (res < 1) { - Message("gpmi_hid_script_remove(): can't remove script from configs, can't find the correspondign config line in %s\n", i->conffile_name); - free(tmpfn); - return -1; - } - - if (rename(tmpfn, i->conffile_name) != 0) { - Message("gpmi_hid_script_remove(): can't remove script from configs, can't move %s to %s.\n", tmpfn, i->conffile_name); - free(tmpfn); - return -1; - } - - free(tmpfn); - return 0; -} - -int gpmi_hid_script_addcfg(hid_gpmi_script_info_t *i) -{ - char *fn, *home; - FILE *f; - - home = getenv ("PCB_RND_GPMI_HOME"); - if (home == NULL) - home = homedir; - - if (homedir != NULL) { - fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb", NULL); - mkdir(fn, 0755); - free(fn); - - fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins", NULL); - mkdir(fn, 0755); - free(fn); - - fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, CONFNAME, NULL); - } - else - fn = Concat("plugins" PCB_DIR_SEPARATOR_S, CONFNAME, NULL); - - f = fopen(fn, "a"); - if (f == NULL) { - Message("gpmi_hid_script_addcfg: can't open %s for write\n", fn); - return -1; - } - - fprintf(f, "\n%s\t%s\n", i->module_name, i->name); - fclose(f); - - free(fn); - return 0; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_plugin.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_plugin.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_plugin.c (nonexistent) @@ -1,218 +0,0 @@ -#include -#include -#include -#include -#include -#include "src/misc.h" -#include "src/event.h" -#include "src/paths.h" -#include "src/error.h" -#include "scripts.h" -#include "manage_scripts.h" - -extern char *homedir; /* detected by pcn-rnd in InitPaths() */ - -/* This function is used to print a detailed GPMI error message */ -void gpmi_hid_print_error(gpmi_err_stack_t *entry, char *string) -{ - Message("[GPMI] %s\n", string); -} - - -int gpmi_hid_gui_inited = 0; -static void ev_gui_init(void *user_data, int argc, event_arg_t *argv[]) -{ - int ev; - char *ev_args; - hid_gpmi_script_info_t *i; - const char *menu[] = {"Plugins", "GPMI scripting", "Scripts", NULL}; - - gui->create_menu(menu, "gpmi_scripts()", "S", "Altg", "Manage GPMI scripts"); - - ev = gpmi_event_find("ACTE_gui_init", &ev_args); - if (ev >= 0) { - for(i = hid_gpmi_script_info; i != NULL; i = i->next) - if (i->module != NULL) - gpmi_event(i->module, ev, argc, argv); - } - gpmi_hid_gui_inited = 1; -} - -static void cmd_reload(char *name) -{ - hid_gpmi_script_info_t *i; - if (name != NULL) { - i = hid_gpmi_lookup(name); - if (i != NULL) - hid_gpmi_reload_module(i); - else - Message("Script %s not found\n", name); - } - else { - for(i = hid_gpmi_script_info; i != NULL; i = i->next) - hid_gpmi_reload_module(i); - } -} - -static int action_gpmi_scripts(int argc, char **argv, Coord x, Coord y) -{ - if (argc == 0) { - gpmi_hid_manage_scripts(); - return 0; - } - if (strcasecmp(argv[0], "reload") == 0) { - if (argc > 1) - cmd_reload(argv[1]); - else - cmd_reload(NULL); - } - else if (strcasecmp(argv[0], "load") == 0) { - if (argc == 3) { - if (hid_gpmi_load_module(NULL, argv[1], argv[2], NULL) == NULL) - Message("Failed to load %s %s\n", argv[1], argv[2]); - } - else - Message("Invalid number of arguments for load\n"); - } - else if (strcasecmp(argv[0], "unload") == 0) { - if (argc == 2) { - hid_gpmi_script_info_t *i = hid_gpmi_lookup(argv[1]); - if (i != NULL) { - if (gpmi_hid_script_unload(i) != 0) { - Message("Failed to unload %s\n", argv[1]); - return 1; - } - } - else { - Message("Failed to unload %s: not loaded\n", argv[1]); - return 1; - } - } - else { - Message("Invalid number of arguments for unload\n"); - return 1; - } - } - else { - Message("Invalid arguments in gpmi_scripts()\n"); - return 1; - } - return 0; -} - -static int action_gpmi_rehash(int argc, char **argv, Coord x, Coord y) -{ - cmd_reload(NULL); - return 0; -} - -static void register_actions() -{ - HID_Action *ctx; - - ctx = malloc(sizeof(HID_Action)); - ctx->name = strdup("gpmi_scripts"); - ctx->need_coord_msg = NULL; - ctx->description = strdup("Manage gpmi scripts"); - ctx->syntax = strdup("TODO"); - ctx->trigger_cb = action_gpmi_scripts; - - hid_register_action(ctx); - - ctx = malloc(sizeof(HID_Action)); - ctx->name = strdup("rehash"); - ctx->need_coord_msg = NULL; - ctx->description = strdup("Reload all gpmi scripts"); - ctx->syntax = strdup("TODO"); - ctx->trigger_cb = action_gpmi_rehash; - - hid_register_action(ctx); -} - -#ifndef PLUGIN_INIT_NAME -#define PLUGIN_INIT_NAME pcb_plugin_init -#endif - -void PLUGIN_INIT_NAME (); - -static void load_base_and_cfg(void) -{ - char *dir, *libdirg, *libdirh, *wdir, *wdirh, *hdirh, *home; - void **gpmi_asm_scriptname; - gpmi_package *scripts = NULL; - - libdirg = resolve_path_inplace(Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins", NULL)); - libdirh = resolve_path_inplace(Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); - wdirh = resolve_path_inplace(Concat ("plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); - wdir = Concat("plugins", NULL); - - home = getenv ("PCB_RND_GPMI_HOME"); - if (home == NULL) - home = homedir; - - hdirh = resolve_path_inplace(Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); - - fprintf(stderr, "gpmi dirs: lg=%s lh=%s wh=%s w=%s hh=%s\n", libdirg, libdirh, wdirh, wdir, hdirh); - - /* first add package search path to all host-specific plugin dirs - This is needed because a script installed in ~/.pcb/plugins/*.conf - (added automatically from, the gui) - could depend on a package being anywhere else - */ - gpmi_path_insert(GPMI_PATH_PACKAGES, libdirh); - gpmi_path_insert(GPMI_PATH_PACKAGES, libdirg); - gpmi_path_insert(GPMI_PATH_PACKAGES, wdirh); - gpmi_path_insert(GPMI_PATH_PACKAGES, hdirh); - - /* the final fallback - append this as loading anything from here is arch-unsafe */ - gpmi_path_append(GPMI_PATH_PACKAGES, wdir); - - - gpmi_err_stack_enable(); - if (gpmi_pkg_load("gpmi_scripts", 0, NULL, NULL, &scripts)) - { - gpmi_err_stack_process_str(gpmi_hid_print_error); - abort(); - } - gpmi_err_stack_destroy(NULL); - - - gpmi_asm_scriptname = gpmi_pkg_resolve(scripts, "gpmi_scripts_asm_scriptname"); - assert(gpmi_asm_scriptname != NULL); - *gpmi_asm_scriptname = gpmi_hid_asm_scriptname; - - register_actions(); - event_bind(EVENT_GUI_INIT, ev_gui_init, NULL, PLUGIN_INIT_NAME); - - hid_gpmi_load_dir(libdirh, 0); - hid_gpmi_load_dir(libdirg, 0); - - dir = Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins", NULL); - hid_gpmi_load_dir(dir, 1); - free(dir); - - if (home != NULL) { - hid_gpmi_load_dir (hdirh, 0); - - dir = resolve_path_inplace(Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins", NULL)); - hid_gpmi_load_dir(dir, 1); - free(dir); - } - - hid_gpmi_load_dir(wdirh, 0); - hid_gpmi_load_dir(wdir, 0); - - free(wdir); - free(wdirh); - free(libdirh); - free(hdirh); -} - - -void PLUGIN_INIT_NAME () -{ - - printf("pcb-gpmi hid is loaded.\n"); - gpmi_init(); - load_base_and_cfg(); -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf (nonexistent) @@ -1,18 +0,0 @@ -@/local/headers - actions.h - -@/local/srcs - actions.c - -@/local/file_name - actions - -@/local/inst_path - actions - -@/local/CFLAGS - -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### - -@@/local/hook/postall - PCB_GPMI_ROOT=../../.. - include $(PCB_GPMI_ROOT)/Makefile.config Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c (nonexistent) @@ -1,120 +0,0 @@ -#include -#include -#include -#include -#include "src/global.h" -#include "src/hid.h" -#include "src/error.h" -#include "actions.h" - -typedef struct acontext_s acontext_t; - -struct acontext_s { - HID_Action action; - char *name; - gpmi_module *module; - acontext_t *next; -}; - -static int action_argc = 0; -static char **action_argv = NULL; - -const char *action_arg(int argn) -{ - if ((argn < 0) || (argn >= action_argc)) - return NULL; - return action_argv[argn]; -} - - -static int action_cb(int argc, char **argv, Coord x, Coord y) -{ - acontext_t *ctx = (acontext_t *)current_action; - int action_argc_old; - char **action_argv_old; - - /* save argc/argv for action_arg() */ - action_argc_old = action_argc; - action_argv_old = action_argv; - action_argc = argc; - action_argv = argv; - - /* call event */ - gpmi_event(ctx->module, ACTE_action, ctx->name, argc, x, y); - - /* restore argc/argv of action_arg() */ - action_argc = action_argc_old; - action_argv = action_argv_old; - - return 0; -} - -static void cleanup_action(gpmi_module *mod, gpmi_cleanup *cl) -{ - acontext_t *ctx = cl->argv[0].p; - hid_remove_action(&ctx->action); - free(ctx->action.name); - if (ctx->action.need_coord_msg != NULL) - free((char *)ctx->action.need_coord_msg); - free((char *)ctx->action.description); - free((char *)ctx->action.syntax); - free(ctx); -} - -int action_register(const char *name, const char *need_xy, const char *description, const char *syntax) -{ - acontext_t *ctx; - - - if ((need_xy != NULL) && (*need_xy == '\0')) - need_xy = NULL; - - - ctx = malloc(sizeof(acontext_t)); - ctx->action.name = strdup(name); - ctx->action.need_coord_msg = strdup_null(need_xy); - ctx->action.description = strdup(description); - ctx->action.syntax = strdup(syntax); - ctx->action.trigger_cb = action_cb; - ctx->name = strdup(name); - ctx->module = gpmi_get_current_module(); - ctx->next = NULL; - - hid_register_action(&ctx->action); - - gpmi_mod_cleanup_insert(ctx->module, cleanup_action, "p", ctx); - - printf("registered.\n"); - return 0; -} - -int action(const char *cmdline) -{ - return hid_parse_command(cmdline); -} - -void create_menu(const char *path_, const char *action, const char *mnemonic, const char *hotkey, const char *tooltip) -{ -#define MENU_MAX 32 - const char *menu[MENU_MAX]; - int n; - char *s, *path = strdup(path_); - - menu[0] = path; - for(n = 1, s = path; *s != '\0'; s++) { - if (*s == '/') { - *s = '\0'; - s++; - menu[n] = s; - n++; - if (n == MENU_MAX-1) { - Message("create_menu(): menu path '%s' too long\n", path_); - break; - } - } - } - menu[n] = NULL; - - gui->create_menu(menu, action, mnemonic, hotkey, tooltip); - free(path); -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep (nonexistent) @@ -1 +0,0 @@ -#Please run make depend! Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h (nonexistent) @@ -1,52 +0,0 @@ -#include - -/* Generated when an action registered by the script is executed. - Arguments: - name: name of the action (as registed using function action_register()) - argc: number of arguments. Arguments can be accessed using function action_arg - x, y: optional coords, if need_xy was not empty at action_register */ -gpmi_define_event(ACTE_action)(const char *name, int argc, int x, int y); - -/* Generated right after gui initialization, before the gui main loop. - Arguments: - argc: number of arguments the gui was initialized with. - argv[]: arguments the gui was initialized with - unaccessible for the scripts. */ -gpmi_define_event(ACTE_gui_init)(int argc, char **argv); - - -/* Generated right before unloading a script to give the script a chance - to clean up. - Arguments: - conffile: the name of the config file that originally triggered laoding the script, or empty if the script was loaded from the gui. */ -gpmi_define_event(ACTE_unload)(const char *conffile); - -/* Register an action in PCB - when the action is executed, event - ACTE_action is generated with the action name. - Multiple actions can be registered. Any action registered by the script - will trigger an ACTE_event sent to the script. - Arguments: - name: name of the action - need_xy: the question the user is asked when he needs to choose a coordinate; if empty, no coordinate is asked - description: description of the action (for the help) - syntax: syntax of the action (for the help) - Returns 0 on success. - */ -int action_register(const char *name, const char *need_xy, const char *description, const char *syntax); - -/* extract the (argn)th event argument for the current action (makes sense only in an ACTE_action event handler */ -const char *action_arg(int argn); - -/* call an existing action using PCB syntax (e.g. foo(1, 2, 3)) - Returns non-zero on error; generally returns value of the action - (which is also non-zero on error). */ -int action(const char *cmdline); - -/* Create a new menu or submenu at path. Missing parents are created - automatically with empty action, mnemonic, hotkey and tooltip. - Arguments: - path: the full path of the new menu - action: this action is executed when the user clicks on the menu - mnemonic: which letter to underline in the menu text (will be the fast-jump-there key once the menu is open) - hotkey: when this key is pressed in the main gui, the action is also triggered; the format is modifiers<Key>letter, where modifiers is Alt, Shift or Ctrl. This is the same syntax that is used in the .res files. - tooltip: short help text */ -void create_menu(const char *path, const char *action, const char *mnemonic, const char *hotkey, const char *tooltip); Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am (nonexistent) @@ -1,15 +0,0 @@ -# This file is package-specific. Do include it in the distribution. -# -# GPMI fingerprint: Makefile.am.ext-pkg - -# End INST_PATH with / -INST_PATH = pcb-gpmi/ -FILE_NAME = actions - -SOURCE = actions.c -HEADER = actions.h - -PKG_LDFLAGS = - -include ../../../Makefile.config -INCLUDES = -I $(PCB_SRC) Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c (nonexistent) @@ -1,19 +0,0 @@ -#include - -int PKG_FUNC(init)() -{ - return 0; -} - -void PKG_FUNC(uninit)() { -} - -void PKG_FUNC(register)() { -} - -int PKG_FUNC(checkver)(int requested) { - if (requested <= 1) - return 0; - - return -1; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf (nonexistent) @@ -1,18 +0,0 @@ -@/local/headers - coordgeo.h - -@/local/srcs - coordgeo.c - -@/local/file_name - coordgeo - -@/local/inst_path - coordgeo - -@/local/CFLAGS - -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### - -@@/local/hook/postall - PCB_GPMI_ROOT=../../.. - include $(PCB_GPMI_ROOT)/Makefile.config Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c (nonexistent) @@ -1,199 +0,0 @@ -#include -#include -#include -#include "coordgeo.h" - -#define POINT_MARK_SIZE 2 -#define PS_SCALE 3 -#define PS_MARGIN 8 - -#define SCALE(v) ((v+PS_MARGIN) * PS_SCALE) - -void line(FILE *ps, int x1, int y1, int x2, int y2) -{ - fprintf(ps, "%d %d moveto\n", SCALE(x1), SCALE(y1)); - fprintf(ps, "%d %d lineto\n", SCALE(x2), SCALE(y2)); -} - -void color(FILE *ps, float r, float g, float b) -{ - static int colorspace=0; - - if (colorspace == 0) { - fprintf(ps, "/DeviceRGB setcolorspace\n"); - colorspace = 1; - } - fprintf(ps, "%f %f %f setcolor\n", r, g, b); -} - - -FILE *ps_start(const char *fn) -{ - FILE *f; - - f = fopen(fn, "w"); - if (f == NULL) - return NULL; - - fprintf(f, "%%!\n"); - - return f; -} - -int ps_draw(FILE *ps, int ID) -{ - cg_obj_t *o; - o = cg_get_object(ID); - assert(o != NULL); - fprintf(ps, "newpath\n"); - - switch(o->type) { - case CG_POINT: - fprintf(ps, "0.1 setlinewidth\n"); - line(ps, o->x1-POINT_MARK_SIZE, o->y1, o->x1+POINT_MARK_SIZE, o->y1); - line(ps, o->x1, o->y1-POINT_MARK_SIZE, o->x1, o->y1+POINT_MARK_SIZE); - break; - case CG_LINE: - fprintf(ps, "0.1 setlinewidth\n"); - line(ps, o->x1, o->y1, o->x2, o->y2); - break; - case CG_VECTOR: - fprintf(ps, "0.1 setlinewidth\n"); - line(ps, o->x1, o->y1, o->x2, o->y2); - break; - case CG_CIRCLE: - fprintf(ps, "0.1 setlinewidth\n"); - fprintf(ps, "%d %d %d %d %d arc\n", SCALE(o->x1), SCALE(o->y1), o->r*PS_SCALE, 0, 360); - break; - case CG_ARC: - fprintf(ps, "0.1 setlinewidth\n"); - fprintf(ps, "%d %d %d %d %d arc\n", SCALE(o->x1), SCALE(o->y1), o->r*PS_SCALE, o->x2, o->y2); - break; - } - - fprintf(ps, "stroke\n"); - return ID; -} - -void ps_end(FILE *ps) -{ - fprintf(ps, "showpage\n"); - fclose(ps); -} - -void test_primitives() -{ - FILE *ps; - - ps = ps_start("primitives.ps"); - cg_destroy_object(ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0))); - cg_destroy_object(ps_draw(ps, cg_new_object(CG_VECTOR, 20, 0, 30, 10, 0))); - cg_destroy_object(ps_draw(ps, cg_new_object(CG_POINT, 40, 5, 0, 0, 0))); - cg_destroy_object(ps_draw(ps, cg_new_object(CG_CIRCLE, 70, 10, 0, 0, 5))); - cg_destroy_object(ps_draw(ps, cg_new_object(CG_ARC, 90, 10, 0, 45, 5))); - ps_end(ps); -} - -void test_parallels() -{ - FILE *ps; - int obj; - - ps = ps_start("parallels.ps"); - - obj = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); - cg_destroy_object(obj); - - obj = ps_draw(ps, cg_new_object(CG_CIRCLE, 70, 10, 0, 0, 5)); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); - cg_destroy_object(obj); - -/* obj = ps_draw(ps, cg_new_object(CG_ARC, 90, 10, 0, 45, 5)); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); - cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); - cg_destroy_object(obj);*/ - - - ps_end(ps); - -} - -void test_perps() -{ - FILE *ps; - int obj; - - ps = ps_start("perpendicular.ps"); - - obj = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); - cg_destroy_object(ps_draw(ps, cg_perp_line(obj, 0,0,4))); - cg_destroy_object(ps_draw(ps, cg_perp_line(obj, 10,10,-4))); - cg_destroy_object(obj); - - ps_end(ps); - -} - -void test_intersect() -{ - FILE *ps; - int o1, o2, i; - cg_obj_t *oi; - - ps = ps_start("intersect.ps"); - - /* two lines, intersecting */ - color(ps, 0, 0, 0); - o1 = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); - o2 = ps_draw(ps, cg_new_object(CG_LINE, 5, 0, 6, 13, 0)); - color(ps, 1, 0, 0); - cg_simplify_object(i = cg_intersect(o1, o2, 1)); - cg_destroy_object(ps_draw(ps, i)); - cg_destroy_object(o1); - cg_destroy_object(o2); - - /* two lines, no visible intersection */ - color(ps, 0, 0, 0); - o1 = ps_draw(ps, cg_new_object(CG_LINE, 20, 0, 30, 10, 0)); - o2 = ps_draw(ps, cg_new_object(CG_LINE, 25, 0, 32, 13, 0)); - color(ps, 1, 0, 0); - cg_simplify_object(i = cg_intersect(o1, o2, 1)); - cg_destroy_object(ps_draw(ps, i)); - cg_destroy_object(o1); - cg_destroy_object(o2); - - /* circle vs. line */ - color(ps, 0, 0, 0); - o1 = ps_draw(ps, cg_new_object(CG_LINE, 40, 0, 55, 15, 0)); - o2 = ps_draw(ps, cg_new_object(CG_CIRCLE, 45, 8, 0, 0, 6)); - color(ps, 1, 0, 0); - cg_simplify_object(i = cg_intersect(o1, o2, 1)); - cg_destroy_object(ps_draw(ps, i)); - cg_destroy_object(o1); - cg_destroy_object(o2); - - /* circle vs. circle */ - color(ps, 0, 0, 0); - o1 = ps_draw(ps, cg_new_object(CG_CIRCLE, 69, 6, 0, 0, 4)); - o2 = ps_draw(ps, cg_new_object(CG_CIRCLE, 65, 8, 0, 0, 6)); - color(ps, 1, 0, 0); - cg_simplify_object(i = cg_intersect(o1, o2, 1)); - cg_destroy_object(ps_draw(ps, i)); - cg_destroy_object(o1); - cg_destroy_object(o2); - - - ps_end(ps); -} - - -int main() -{ - test_primitives(); - test_parallels(); - test_perps(); - test_intersect(); -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c (nonexistent) @@ -1,578 +0,0 @@ -#include -#include -#include "coordgeo.h" -cg_obj_t *cg_objs = NULL; -int cg_objs_used = 0, cg_objs_alloced = 0; - -#define DEGMPY 10000.0 -#define PI 3.141592654 - -#define OBJ(i) cg_objs[i] -#define OBJ_VALID(i) ((i >= 0) && (i < cg_objs_used)) - -/* todo */ -#define invalid -0xFFFF - -static int oalloc() -{ - int id; - if (cg_objs_used >= cg_objs_alloced) { - cg_objs_alloced = cg_objs_used + 128; - cg_objs = realloc(cg_objs, sizeof(cg_obj_t) * cg_objs_alloced); - } - id = cg_objs_used; - cg_objs_used++; - return id; -} - -static void ofree(int id) -{ - /* todo */ -} - -int cg_new_object(cg_obj_type_t type, int x1, int y1, int x2, int y2, int r) -{ - int id; - - id = oalloc(); - OBJ(id).type = type; - OBJ(id).x1 = x1; - OBJ(id).y1 = y1; - OBJ(id).x2 = x2; - OBJ(id).y2 = y2; - OBJ(id).r = r; - return id; -} - -static inline int cg_clone_object_(cg_obj_t *o) -{ - int id; - - id = oalloc(); - OBJ(id) = *o; - return id; -} - -int cg_clone_object(int objID) -{ - return cg_clone_object_(&OBJ(objID)); -} - -/* destroys an object by ID */ -void cg_destroy_object(int ID) -{ - ofree(ID); -} - -/* -- field accessors -- */ -cg_obj_type_t cg_get_type(int objID) -{ - return OBJ(objID).type; -} - -int cg_get_coord(int objID, cg_coord_t coordname) -{ - switch(coordname) { - case CG_X1: return OBJ(objID).x1; - case CG_Y1: return OBJ(objID).y1; - case CG_X2: return OBJ(objID).x2; - case CG_Y2: return OBJ(objID).y2; - case CG_R: return OBJ(objID).r; - } - return invalid; -} - -void cg_set_coord(int objID, cg_coord_t coordname, int newvalue) -{ - switch(coordname) { - case CG_X1: OBJ(objID).x1 = newvalue; - case CG_Y1: OBJ(objID).y1 = newvalue; - case CG_X2: OBJ(objID).x2 = newvalue; - case CG_Y2: OBJ(objID).y2 = newvalue; - case CG_R: OBJ(objID).r = newvalue; - } -} - - -/* -- object operations -- */ -double cg_dist_(int x1, int y1, int x2, int y2) -{ - int dx, dy; - - dx = x2 - x1; - dy = y2 - y1; - return sqrt(dx * dx + dy * dy); -} - -int cg_solve_quad(double a, double b, double c, double *x1, double *x2) -{ - double d; - - d = b * b - 4 * a * c; - if (d < 0) - return 0; - if (d != 0) - d = sqrt(d); - - if (x1 != NULL) - *x1 = (-b + d) / (2 * a); - - if (x2 != NULL) - *x2 = (-b - d) / (2 * a); - - if (d == 0) - return 1; - return 2; -} - - -/* return ID to a new object which is parallel obj in distance dist - - for a line dist > 0 means a new line right to the original - (looking from x1;y1 towards x2;y2) - - for arc the same rule applies, looking from angle x2 towards y2 - - for circle dist > 0 means smaller concentric circle - - for point and vector always returns invalid -*/ -int cg_para_obj(int objID, int dist) -{ - cg_obj_t v1, v2; - int rid; - - switch(OBJ(objID).type) { - case CG_POINT: - case CG_VECTOR: - return -1; - case CG_ARC: - /* TODO */ - abort(); - break; - case CG_CIRCLE: - rid = cg_clone_object(objID); - OBJ(rid).r -= dist; - return rid; - case CG_LINE: - cg_perp_line_(&OBJ(objID), &v1, OBJ(objID).x1, OBJ(objID).y1, dist); - cg_perp_line_(&OBJ(objID), &v2, OBJ(objID).x2, OBJ(objID).y2, dist); - rid = oalloc(); - OBJ(rid).type = CG_LINE; - OBJ(rid).x1 = v1.x2; - OBJ(rid).y1 = v1.y2; - OBJ(rid).x2 = v2.x2; - OBJ(rid).y2 = v2.y2; - OBJ(rid).r = 0; - return rid; - } - return -1; -} - -void cg_perp_line_(const cg_obj_t *i, cg_obj_t *o, int xp, int yp, int len) -{ - double dx, dy, dl; - - dx = -(i->y2 - i->y1); - dy = +(i->x2 - i->x1); - dl = sqrt(dx * dx + dy * dy); - dx = dx / dl; - dy = dy / dl; - - o->type = CG_LINE; - o->x1 = xp; - o->y1 = yp; - o->x2 = round((double)xp + dx * (double)len); - o->y2 = round((double)yp + dy * (double)len); - o->r = 0; -} - - -/* return ID to a new line which is perpendicular to line1 and starts at - point xp;yp and is len long */ -int cg_perp_line(int line1ID, int xp, int yp, int len) -{ - int id; - - id = oalloc(); - cg_perp_line_(&OBJ(line1ID), &OBJ(id), xp, yp, len); - - return id; -} - -int cg_ison_line_(cg_obj_t *l, int x, int y, int extend) -{ - int vx, vy; - - vx = l->x2 - l->x1; - vy = l->y2 - l->y1; - - /* is the point on the extended line? */ - if ((vy * x - vx * y) != (vy * l->x1 - vy * l->y1)) - return 0; - - if ((!extend) && ((x < l->x1) || (x > l->x2))) - return 0; - return 1; -} - -int cg_ison_arc_(cg_obj_t *a, int x, int y, int extend) -{ - double deg; - - /* is the point on the circle? */ - if (cg_dist_(a->x1, a->y1, x, y) != a->r) - return 0; - - /* for circles (or an extended arc, which is just a circle) this means the point must be on */ - if (extend || (a->type == CG_CIRCLE)) - return 1; - - /* check if the point is between start and end angles */ - deg = atan2(y - a->y1, x - a->x1) * DEGMPY; - if ((deg >= a->x2) && (deg >= a->y2)) - return 1; - - return 0; -} - -int cg_ison_point_(cg_obj_t *p, int x, int y) -{ - return (p->x1 == x) && (p->y1 == y); -} - -int cg_ison_(cg_obj_t *o, int x, int y, int extend) -{ - switch(o->type) { - case CG_POINT: return cg_ison_point_(o, x, y); - case CG_VECTOR: return 1; - case CG_LINE: return cg_ison_line_(o, x, y, extend); - case CG_ARC: return cg_ison_arc_(o, x, y, extend); - case CG_CIRCLE: return cg_ison_circle_(o, x, y); - } - - /* can't get here */ - abort(); - return 0; -} - -/* intersection of 2 lines (always returns 1) */ -int cg_intersect_ll(cg_obj_t *l1, cg_obj_t *l2, cg_obj_t *o) -{ - double ua, ub, xi, yi, X1, Y1, X2, Y2, X3, Y3, X4, Y4, tmp; - - /* maths from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ */ - - X1 = l1->x1; - X2 = l1->x2; - X3 = l2->x1; - X4 = l2->x2; - Y1 = l1->y1; - Y2 = l1->y2; - Y3 = l2->y1; - Y4 = l2->y2; - - tmp = ((Y4-Y3)*(X2-X1) - (X4-X3)*(Y2-Y1)); - ua=((X4-X3)*(Y1-Y3) - (Y4-Y3)*(X1-X3)) / tmp; - ub=((X2-X1)*(Y1-Y3) - (Y2-Y1)*(X1-X3)) / tmp; - xi = X1 + ua * (X2 - X1); - yi = Y1 + ua * (Y2 - Y1); - - o->type = CG_LINE; - o->x1 = o->x2 = round(xi); - o->y1 = o->y2 = round(yi); - o->r = 0; - return 1; -} - -/* intersections of a line and a circle (returns number of possible intersections) */ -int cg_intersect_lc(cg_obj_t *l, cg_obj_t *c, cg_obj_t *o) -{ - int x1, y1, vx, vy, a, vx2, ints; - double A, B, C, X1, X2, Y1, Y2; - - /* first we transform the line to the coordinate system with origo in the - center of the circle - this will simplify the equations */ - x1 = l->x1 - c->x1; - y1 = l->y1 - c->y1; - vx = l->x2 - l->x1; - vy = l->y2 - l->y1; - - /* some cache */ - a = vy * x1 - vx * y1; - vx2 = vx * vx; - - /* this quadratic equation results in the two intersections, X1 and X2 */ - A = 1+vy*vy/vx2; - B = - 2*a*vy / (vx2); - C = a*a / vx2 - c->r * c->r; - - ints = cg_solve_quad(A, B, C, &X1, &X2); - if (ints == 0) - return 0; - - /* knowing X1 and X2 we can easily get Y1 and Y2 */ - Y1 = (a - vy * X1) / (-vx); - Y2 = (a - vy * X2) / (-vx); - - /* transoform back to the original coordinate system */ - X1 += c->x1; - X2 += c->x1; - Y1 += c->y1; - Y2 += c->y1; - - /* set up return line and return number of intersections */ - o->type = CG_LINE; - o->x1 = X1; - o->y1 = Y1; - o->x2 = X2; - o->y2 = Y2; - o->r = 0; - return ints; -} - -/* intersections of 2 circles (returns number of possible intersections) */ -int cg_intersect_cc(cg_obj_t *c1, cg_obj_t *c2, cg_obj_t *o) -{ - double d, a, h; - int P2x, P2y; - - d = cg_dist_(c1->x1, c1->y1, c2->x1, c2->y1); - - if (d > c1->r + c2->r) - return 0; /* separate */ - if (d < abs(c1->r - c2->r)) - return 0; /* contained */ - if ((d == 0) && (c1->r == c2->r)) - return -1; /* they are the same circle */ - - /* some temps */ - a = (double)(c1->r * c1->r - c2->r * c2->r + d * d) / (2.0 * d); - h = sqrt(c1->r * c1->r - a * a); - P2x = c1->x1 + a * (c2->x1 - c1->x1) / d; - P2y = c1->y1 + a * (c2->y1 - c1->y1) / d; - - /* final coordinates */ - o->type = CG_LINE; - o->x1 = P2x + h * (c2->y1 - c1->y1) / d; - o->y1 = P2y - h * (c2->x1 - c1->x1) / d; - o->x2 = P2x - h * (c2->y1 - c1->y1) / d; - o->y2 = P2y + h * (c2->x1 - c1->x1) / d; - - if (d == c1->r + c2->r) - return 1; - return 2; -} - - -int cg_intersect_(cg_obj_t *i1, cg_obj_t *i2, cg_obj_t *o) -{ - switch(i1->type) { - case CG_VECTOR: - /* invalid */ - return -1; - case CG_POINT: - /* TODO: ison */ - break; - case CG_LINE: - switch(i2->type) { - case CG_VECTOR: - /* invalid */ - return -1; - case CG_POINT: - /* TODO: ison */ - break; - case CG_LINE: - return cg_intersect_ll(i1, i2, o); - case CG_CIRCLE: - case CG_ARC: - return cg_intersect_lc(i1, i2, o); - } - return -1; - case CG_CIRCLE: - case CG_ARC: - switch(i2->type) { - case CG_VECTOR: - /* invalid */ - return -1; - case CG_POINT: - /* TODO: ison */ - break; - case CG_LINE: - return cg_intersect_lc(i2, i1, o); - case CG_CIRCLE: - case CG_ARC: - return cg_intersect_cc(i1, i2, o); - } - return -1; - } - return -1; -} - -int cg_intersect(int obj1ID, int obj2ID, int extend) -{ - cg_obj_t res; - int ints; - - ints = cg_intersect_(&OBJ(obj1ID), &OBJ(obj2ID), &res); - - /* if we needed to extend, we shouldn't care if the intersections - are on the objects. */ - if (extend) - return cg_clone_object_(&res); - - - while(1) { - if (ints == 0) - return -1; - - if ((!cg_ison_(&OBJ(obj1ID), res.x1, res.y1, 0)) || (!cg_ison_(&OBJ(obj2ID), res.x1, res.y1, 0))) { - /* x1;y1 is not on the objects. make x2;y2 the new x1;y1 and test again */ - res.x1 = res.x2; - res.y1 = res.y2; - ints--; - } - else - break; - } - - /* x1;y1 is on the objects; check x2;y2 if we still have 2 intersections */ - if ((ints == 2) && ((!cg_ison_(&OBJ(obj1ID), res.x2, res.y2, 0)) || (!cg_ison_(&OBJ(obj2ID), res.x2, res.y2, 0)))) { - /* x2;y2 not on the objects, kill it */ - res.x2 = res.x1; - res.y2 = res.y1; - ints = 1; - } - - return cg_clone_object_(&res); -} - -/* Truncate an object at x;y. Point x;y must be on the object. Optionally - invert which part is kept. Default: - - line: keep the part that originates from x1;y1 - - arc: keep the segment that is closer to the starting angle (x2) - - circle: always fails - - point: always fails - - vector: always fails - Returns 0 on success. -*/ -int cg_truncate_(cg_obj_t *o, int x, int y, int invert_kept) -{ - double a; - - /* point is not on the object */ - if (!cg_ison_(o, x, y, 0)) - return 1; - - switch(o->type) { - case CG_VECTOR: - case CG_POINT: - case CG_CIRCLE: - return 2; - case CG_LINE: - if (!invert_kept) { - o->x2 = x; - o->y2 = y; - } - else { - o->x1 = x; - o->y1 = y; - } - break; - case CG_ARC: - a = atan2(y - o->y1, x - o->x1) * DEGMPY; - if (!invert_kept) - o->y2 = a; - else - o->x2 = a; - break; - } - return 0; -} - -int cg_truncate(int objID, int x, int y, int invert_kept) -{ - return cg_truncate_(&OBJ(objID), x, y, invert_kept); -} - -/* cut target object with cutting edge object; optionally invert which - part is kept of target. Default: - - when line cuts, looking from x1;y1 towards x2;y2, right is kept - - when circle or arc cuts, we are "walking" clock-wise, right is kept - (in short, inner part is kept) - Returns 0 on success. -*/ -int cg_cut_(cg_obj_t *t, cg_obj_t *c, int invert_kept) -{ - cg_obj_t intersects; - int num_intersects, ni; - - num_intersects = cg_intersect_(t, c, &intersects); - if (num_intersects < 1) - return 1; - - for(; num_intersects > 0; num_intersects--) - { - switch(c->type) { - case CG_POINT: - case CG_VECTOR: - return 1; - case CG_LINE: - /* TODO: leftof */ - return 1; - case CG_CIRCLE: - case CG_ARC: - /* TODO: leftof */ - break; - } - /* shift intersection */ - intersects.x1 = intersects.x2; - intersects.y1 = intersects.y2; - } - return 0; -} - -int cg_cut(int targetID, int cutting_edgeID, int invert_kept); - -cg_obj_t *cg_get_object(int ID) -{ - if (OBJ_VALID(ID)) - return &OBJ(ID); - else - return NULL; -} - -int cg_simplify_object_(cg_obj_t *o) -{ - int ret = 0; /* no direct returns because CG_ARC can have more than one optimization */ - switch(o->type) { - case CG_LINE: - if ((o->x1 == o->x2) && (o->y1 == o->y2)) { - o->type = CG_POINT; - ret++; - break; - } - break; - case CG_ARC: - if ((fabs(o->x2 - o->y2) * DEGMPY) >= 2*PI) { - o->type = CG_CIRCLE; - ret++; - } - /* intended fall trough for r==0 check */ - case CG_CIRCLE: - if (o->r == 0) { - o->type = CG_POINT; - ret++; - break; - } - break; - default: - /* no simplification possible */ - ; - } - return ret; -} - - -int cg_simplify_object(int ID) -{ - if (OBJ_VALID(ID)) - return cg_simplify_object_(&OBJ(ID)); - return -1; -} \ No newline at end of file Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep (nonexistent) @@ -1 +0,0 @@ -#Please run make depend! Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h (nonexistent) @@ -1,123 +0,0 @@ -#include - -typedef enum cg_obj_type_e { - CG_POINT, /* x1;y1 */ - CG_LINE, /* from x1;y1 to x2;y2 */ - CG_VECTOR, /* x1;y1 (not associated with a point) */ - CG_CIRCLE, /* center x1;y1, radius r */ - CG_ARC /* center x1;y1, radius r, from x2 rad to y2 rad */ -} cg_obj_type_t; - -typedef enum cg_coord_e { - CG_X1, - CG_Y1, - CG_X2, - CG_Y2, - CG_R -} cg_coord_t; - - -/* -- object administration -- */ -/* returns ID to the new object */ -int cg_new_object(cg_obj_type_t type, int x1, int y1, int x2, int y2, int r); - -/* cloned an existing object and returns ID to the new object */ -int cg_clone_object(int objID); - -/* destroys an object by ID */ -void cg_destroy_object(int ID); - -/* -- field accessors -- */ -cg_obj_type_t cg_get_type(int objID); -int cg_get_coord(int objID, cg_coord_t coordname); -void cg_set_coord(int objID, cg_coord_t coordname, int newvalue); - - -/* -- object operations -- */ -/* return ID to a new object which is parallel obj in distance dist - - for a line dist > 0 means a new line right to the original - (looking from x1;y1 towards x2;y2) - - for arc the same rule applies, looking from angle x2 towards y2 - - for circle dist > 0 means smaller concentric circle - - for point and vector always returns invalid -*/ -int cg_para_obj(int objID, int dist); - -/* return ID to a new line which is perpendicular to line1 and starts at - point xp;yp and is len long */ -int cg_perp_line(int line1ID, int xp, int yp, int len); - -/* returns ID to a line which marks the intersection(s) of two objects or - returns -1 if there's no intersection. If there's only one intersection, - the start and end point of the line is the same point. With the current - primitives, there can not be more than 2 intersections between 2 objects, - except when they have infinite amount of intersections: - - overlapping lines - - overlapping arcs - - two circles with the same radius and center - If extend is non-zero, the objects are extended during the calculation. - For lines this means infinite length, for arcs this means handling them as - circles. -*/ -int cg_intersect(int obj1ID, int obj2ID, int extend); - -/* Truncate an object at x;y. Point x;y must be on the object. Optionally - invert which part is kept. Default: - - line: keep the part that originates from x1;y1 - - arc: keep the segment that is closer to the starting angle (x2) - - circle: always fails - - point: always fails - - vector: always fails - Returns 0 on success. -*/ -int cg_truncate(int objID, int x, int y, int invert_kept); - -/* cut target object with cutting edge object; optionally invert which - part is kept of target. Defaults: - - when line cuts, looking from x1;y1 towards x2;y2, right is kept - - when circle or arc cuts, we are "walking" clock-wise, right is kept - (in short, inner part is kept) - - vector and point fails - Returns 0 on success. -*/ -int cg_cut(int targetID, int cutting_edgeID, int invert_kept); - -/* Convert object to simpler form, if possible: - - if x1;y1 and x2;y2 are equal in a line, it is converted to a point - - if radius of a circle or arc is zero, it is converted to a point - - if an arc is a full circle, convert it to a circle - Returns number of simplifications (0, 1 or 2) issued or -1 for - invalid object ID. -*/ -int cg_simplify_object(int ID); - - -/* these are for C API, scripts have no direct access */ -typedef struct cg_obj_s { - cg_obj_type_t type; - int x1, y1, x2, y2; - int r; -} cg_obj_t; - -extern cg_obj_t *cg_objs; -extern int cg_objs_used, cg_objs_alloced; - -nowrap cg_obj_t *cg_get_object(int ID); - -/* create a line in o that is perpendicular to i and starts at point xp and yp */ -nowrap void cg_perp_line_(const cg_obj_t *i, cg_obj_t *o, int xp, int yp, int len); - -/* distance */ -nowrap double cg_dist_(int x1, int y1, int x2, int y2); - -/* is point on the object? Extend means the object is extended (lines become - infinite long, arcs become circles). Vector always returns 1. */ -nowrap int cg_ison_(cg_obj_t *o, int x, int y, int extend); -nowrap int cg_ison_line_(cg_obj_t *l, int x, int y, int extend); -nowrap int cg_ison_arc_(cg_obj_t *a, int x, int y, int extend); -nowrap int cg_ison_point_(cg_obj_t *p, int x, int y); -#define cg_ison_circle_(c, x, y) cg_ison_arc_(c, x, y, 1) - -/* these calls are the low level versions of the ones defined for scripts above */ -nowrap int cg_simplify_object_(cg_obj_t *o); - Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am (nonexistent) @@ -1,17 +0,0 @@ -# This file is package-specific. Do include it in the distribution. -# -# GPMI fingerprint: Makefile.am.ext-pkg - -# End INST_PATH with / -INST_PATH = pcb-gpmi/ -FILE_NAME = coordgeo - -SOURCE = coordgeo.c -HEADER = coordgeo.h - -PKG_LDFLAGS = -lm - -include ../../../Makefile.config -INCLUDES = -I $(PCB_SRC) - -test: test.o coordgeo.o Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c (nonexistent) @@ -1,19 +0,0 @@ -#include - -int PKG_FUNC(init)() -{ - return 0; -} - -void PKG_FUNC(uninit)() { -} - -void PKG_FUNC(register)() { -} - -int PKG_FUNC(checkver)(int requested) { - if (requested <= 1) - return 0; - - return -1; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf (nonexistent) @@ -1,18 +0,0 @@ -@/local/headers - dialogs.h - -@/local/srcs - dialogs.c - -@/local/file_name - dialogs - -@/local/inst_path - dialogs - -@/local/CFLAGS - -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### - -@@/local/hook/postall - PCB_GPMI_ROOT=../../.. - include $(PCB_GPMI_ROOT)/Makefile.config Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c (nonexistent) @@ -1,90 +0,0 @@ -#include "dialogs.h" -#include "src/error.h" - -extern HID *gui; - -void dialog_log(const char *msg) -{ - if (gui == NULL) - fprintf(stderr, "couldn't find gui for log: \"%s\"\n", msg); - else - Message("%s", msg); -} - -#define empty(s) (((s) == NULL) || ((*s) == '\0')) -int dialog_confirm(const char *msg, const char *ok, const char *cancel) -{ - if (gui == NULL) { - fprintf(stderr, "couldn't find gui for dialog_confirm: \"%s\"\n", msg); - return -1; - } - - if (empty(ok)) - ok = NULL; - if (empty(cancel)) - cancel = NULL; - - return gui->confirm_dialog(msg, cancel, ok, NULL); -} -#undef empty - -void dialog_report(const char *title, const char *msg) -{ - if (gui == NULL) - fprintf(stderr, "couldn't find gui for dialog_report: \"%s\" \"%s\"\n", title, msg); - else - gui->report_dialog(title, msg); -} - -dynamic char *dialog_prompt(const char *msg, const char *default_) -{ - if (gui == NULL) { - fprintf(stderr, "couldn't find gui for dialog_prompt: \"%s\" \"%s\"\n", msg, default_); - return NULL; - } - else - return gui->prompt_for(msg, default_); -} - -dynamic char *dialog_fileselect(const char *title, const char *descr, char *default_file, char *default_ext, const char *history_tag, multiple dialog_fileselect_t flags) -{ - if (gui == NULL) { - fprintf(stderr, "couldn't find gui for dialog_fileselect\n"); - return NULL; - } - else - return gui->fileselect(title, descr, default_file, default_ext, history_tag, flags); -} - -void dialog_beep(void) -{ - if (gui == NULL) - fprintf(stderr, "couldn't find gui for dialog_beep\n"); - else - gui->beep(); -} - -int dialog_progress(int so_far, int total, const char *message) -{ - if (gui == NULL) { - fprintf(stderr, "couldn't find gui for dialog_process: %d/%d \"%s\"\n", so_far, total, message); - return -1; - } - return gui->progress(so_far, total, message); -} - -int dialog_attribute(hid_t *hid, const char *title, const char *descr) -{ - if (gui == NULL) { - fprintf(stderr, "couldn't find gui for dialog_attribute: \"%s\" \"%s\"\n", title, descr); - return -1; - } - - if (hid->result != NULL) { - /* TODO: free string fields to avoid memleaks */ - } - else - hid->result = calloc(sizeof(HID_Attribute), hid->attr_num); - - return gui->attribute_dialog(hid->attr, hid->attr_num, hid->result, title, descr); -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep (nonexistent) @@ -1 +0,0 @@ -#Please run make depend! Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h (nonexistent) @@ -1,74 +0,0 @@ -#include -#include "src/global.h" -#define FROM_PKG -#include "hid/hid.h" - -/* Filter on what files a file select dialog should list */ -typedef enum dialog_fileselect_e { - FS_NONE = 0, /* none of the below */ - FS_READ = 1, /* when the selected file will be read, not written (HID_FILESELECT_READ) */ - FS_NOT_EXIST = 2, /* the function calling hid->fileselect will deal with the case when the selected file already exists. If not given, then the gui will prompt with an "overwrite?" prompt. Only used when writing. (HID_FILESELECT_MAY_NOT_EXIST) */ - FS_TEMPLATE = 4 /* the call is supposed to return a file template (for gerber output for example) instead of an actual file. Only used when writing. (HID_FILESELECT_IS_TEMPLATE) */ -} dialog_fileselect_t; -gpmi_keyword *kw_dialog_fileselect_e; /* of dialog_fileselect_t */ - -/* Append a msg to the log (log window and/or stderr). */ -void dialog_log(const char *msg); - -/* Ask the user for confirmation (usually using a popup). Returns 0 for - cancel and 1 for ok. - Arguments: - msg: message to the user - ok: label of the OK button - cancel: label of the cancel button - Arguments "ok" and "cancel" may be empty (or NULL) in which - case the GUI will use the default (perhaps localized) labels for - those buttons. */ -int dialog_confirm(const char *msg, const char *ok, const char *cancel); - - -/* Pop up a report dialog. - Arguments: - title: title of the window - msg: message */ -void dialog_report(const char *title, const char *msg); - -/* Ask the user to input a string (usually in a popup). - Arguments: - msg: message or question text - default_: default answer (this may be filled in on start) - Returns the answer. */ -dynamic char *dialog_prompt(const char *msg, const char *default_); - -/* Pops up a file selection dialog. - Arguments: - title: window title - descr: description - default_file_ - default_ext: default file name extension - history_tag - flags: one or more flags (see below) - Returns the selected file or NULL (empty). */ -dynamic char *dialog_fileselect(const char *title, const char *descr, char *default_file_, char *default_ext, const char *history_tag, multiple dialog_fileselect_t flags); - -/* Audible beep */ -void dialog_beep(void); - -/* Request the GUI hid to draw a progress bar. - Arguments: - int so_far: achieved state - int total: maximum state - const char *message: informs the users what they are waiting for - If so_far is bigger than total, the progress bar is closed. - Returns nonzero if the user wishes to cancel the operation. -*/ -int dialog_progress(int so_far, int total, const char *message); - - -/* Pop up an attribute dialog; content (widgets) of the dialog box are coming - from hid (see the hid package). - Arguments: - hid: widgets - title: title of the window - descr: descripting printed in the dialog */ -int dialog_attribute(hid_t *hid, const char *title, const char *descr); Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am (nonexistent) @@ -1,16 +0,0 @@ -# This file is package-specific. Do include it in the distribution. -# -# GPMI fingerprint: Makefile.am.ext-pkg - -# End INST_PATH with / -INST_PATH = pcb-gpmi/ -FILE_NAME = dialogs - -SOURCE = dialogs.c -HEADER = dialogs.h - -PKG_LDFLAGS = - -PCB_GPMI_ROOT=../../.. -include $(PCB_GPMI_ROOT)/Makefile.config -INCLUDES = -I.. -I../.. -I $(PCB_SRC) Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf (nonexistent) @@ -1,20 +0,0 @@ -@/local/headers - hid.h - hid_events.h - -@/local/srcs - hid.c - hid_callbacks.c - -@/local/file_name - hid - -@/local/inst_path - hid - -@/local/CFLAGS - -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### - -@@/local/hook/postall - PCB_GPMI_ROOT=../../.. - include $(PCB_GPMI_ROOT)/Makefile.config Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c (nonexistent) @@ -1,172 +0,0 @@ -#include -#include "src/global.h" -#include "src/hid.h" -#include "src/data.h" -#include "src/hid/hidint.h" -#define FROM_PKG -#include "hid.h" -#include "hid_events.h" -#include "hid_callbacks.h" - -/* TODO */ -#define MAX_LAYER 16 - -HID_Attribute *gpmi_hid_get_export_options(int *num) -{ - hid_t *h; - - h = hid_gpmi_data_get(exporter); - - if (h == NULL) - return NULL; - - gpmi_event(h->module, HIDE_get_export_options, h); - - if (num != NULL) - *num = h->attr_num; - return h->attr; -} - -static char *gcs = "abcdefghijklmnopqrstuvxyz"; -hidGC gpmi_hid_make_gc(void) -{ - hidGC ret; - hid_t *h = hid_gpmi_data_get(exporter); - - /* TODO: fix gc handling... */ - h->new_gc = (void *)(gcs++); - gpmi_event(h->module, HIDE_make_gc, h, h->new_gc); - ret = h->new_gc; - h->new_gc = NULL; - return ret; -} - -void gpmi_hid_destroy_gc(hidGC gc) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_destroy_gc, h, gc); -} - -void gpmi_hid_do_export(HID_Attr_Val * options) -{ - hid_t *h = hid_gpmi_data_get(exporter); - int save_ons[MAX_LAYER + 2]; - BoxType region; - - h->result = options; - gpmi_event(h->module, HIDE_do_export_start, h); - - hid_save_and_show_layer_ons(save_ons); - - region.X1 = 0; - region.Y1 = 0; - region.X2 = PCB->MaxWidth; - region.Y2 = PCB->MaxHeight; - - hid_expose_callback(h->hid, ®ion, 0); - hid_restore_layer_ons(save_ons); - gpmi_event(h->module, HIDE_do_export_finish, h); - h->result = NULL; -} - -void gpmi_hid_parse_arguments(int *pcbargc, char ***pcbargv) -{ - /* Do nothing for now */ - hid_parse_command_line(pcbargc, pcbargv); -} - -void gpmi_hid_set_crosshair(int x, int y, int cursor_action) -{ - /* Do nothing */ -} - -int gpmi_hid_set_layer(const char *name, int group, int empty) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_layer, h, name, group, empty); - return 1; -} - -void gpmi_hid_set_color(hidGC gc, const char *name) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_color, h, gc, name); -} - -void gpmi_hid_set_line_cap(hidGC gc, EndCapStyle style) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_line_cap, h, gc, style); -} - -void gpmi_hid_set_line_width(hidGC gc, Coord width) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_line_width, h, gc, width); -} - -void gpmi_hid_set_draw_xor(hidGC gc, int xor) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_draw_xor, h, gc, xor); -} - -void gpmi_hid_set_draw_faded(hidGC gc, int faded) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_set_draw_faded, h, gc, faded); -} - -void gpmi_hid_draw_line(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_draw_line, h, gc, x1, y1, x2, y2); -} - -void gpmi_hid_draw_arc(hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_draw_arc, h, gc, cx, cy, xradius, yradius, start_angle, delta_angle); -} - -void gpmi_hid_draw_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_draw_rect, h, gc, x1, y1, x2, y2); -} - -void gpmi_hid_fill_circle(hidGC gc, Coord cx, Coord cy, Coord radius) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_fill_circle, h, gc, cx, cy, radius); -} - -void gpmi_hid_fill_polygon(hidGC gc, int n_coords, Coord *x, Coord *y) -{ - hid_t *h = hid_gpmi_data_get(exporter); - /* TODO: need accessor for these */ - gpmi_event(h->module, HIDE_fill_polygon, h, gc, x, y); -} - -void gpmi_hid_fill_pcb_polygon(hidGC gc, PolygonType *poly, const BoxType *clip_box) -{ - /* TODO */ -} - -void gpmi_hid_fill_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_fill_rect, h, gc, x1, y1, x2, y2); -} - -void gpmi_hid_use_mask(int use_it) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_use_mask, h, use_it); -} - -void gpmi_hid_fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask) -{ - hid_t *h = hid_gpmi_data_get(exporter); - gpmi_event(h->module, HIDE_fill_pcb_pv, h, fg_gc, bg_gc, pad, drawHole, mask); -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep (nonexistent) @@ -1 +0,0 @@ -#Please run make depend! Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c (nonexistent) @@ -1,304 +0,0 @@ -#include -#include -#include -#include -#include "src/global.h" -#include "src/error.h" -#include "src/hid.h" -#include "src/hid/common/hidnogui.h" -#include "src/hid/hidint.h" -#include "src/pcb-printf.h" -#define FROM_PKG -#include "hid.h" -#include "hid_callbacks.h" - - -void hid_gpmi_data_set(hid_t *h, void *data) -{ - h->hid->user_context = data; -} - -hid_t *hid_gpmi_data_get(HID *h) -{ - if (h == NULL) - return NULL; - return (hid_t *)h->user_context; -} - -hid_t *hid_create(char *hid_name, char *description) -{ - hid_t *h; - - h = calloc(sizeof(hid_t), 1); - h->hid = calloc(sizeof(HID), 1); - - common_nogui_init (h->hid); - - h->module = gpmi_get_current_module(); - - h->hid->name = strdup(hid_name); - h->hid->description = strdup(description); - h->hid->exporter = 1; - h->hid->gui = 0; - h->hid->struct_size = sizeof(HID); - - h->hid->get_export_options = gpmi_hid_get_export_options; - h->hid->make_gc = gpmi_hid_make_gc; - h->hid->destroy_gc = gpmi_hid_destroy_gc; - h->hid->do_export = gpmi_hid_do_export; - h->hid->parse_arguments = gpmi_hid_parse_arguments; - h->hid->set_crosshair = gpmi_hid_set_crosshair; - h->hid->set_layer = gpmi_hid_set_layer; - h->hid->set_color = gpmi_hid_set_color; - h->hid->set_line_cap = gpmi_hid_set_line_cap; - h->hid->set_line_width = gpmi_hid_set_line_width; - h->hid->set_draw_xor = gpmi_hid_set_draw_xor; - h->hid->set_draw_faded = gpmi_hid_set_draw_faded; - h->hid->draw_line = gpmi_hid_draw_line; - h->hid->draw_arc = gpmi_hid_draw_arc; - h->hid->draw_rect = gpmi_hid_draw_rect; - h->hid->fill_circle = gpmi_hid_fill_circle; - h->hid->fill_polygon = gpmi_hid_fill_polygon; - h->hid->fill_pcb_polygon = gpmi_hid_fill_pcb_polygon; - h->hid->fill_rect = gpmi_hid_fill_rect; - h->hid->fill_pcb_pv = gpmi_hid_fill_pcb_pv; - h->hid->use_mask = gpmi_hid_use_mask; - - h->attr_num = 0; - h->attr = NULL; - h->new_gc = NULL; - - hid_gpmi_data_set(h, h); - return h; -} - -dynamic char *hid_get_attribute(hid_t *hid, int attr_id) -{ - const char *res; - char buff[128]; - HID_Attr_Val *v; - - if ((hid == NULL) || (attr_id < 0) || (attr_id >= hid->attr_num) || (hid->result == NULL)) - return 0; - - res = NULL; - - v = &(hid->result[attr_id]); - switch(hid->type[attr_id]) { - case HIDA_Boolean: - if (v->int_value) - res = "true"; - else - res = "false"; - break; - case HIDA_Integer: - snprintf(buff, sizeof(buff), "%d", v->int_value); - res = buff; - break; - case HIDA_Real: - snprintf(buff, sizeof(buff), "%f", v->real_value); - res = buff; - break; - case HIDA_String: - case HIDA_Label: - case HIDA_Path: - res = v->str_value; - break; - case HIDA_Enum: - res = hid->attr[attr_id].enumerations[v->int_value]; -/* printf("res='%s' %d\n", res, v->int_value);*/ - break; - case HIDA_Coord: - pcb_sprintf(buff, "%mI", v->coord_value); - res = buff; - break; - case HIDA_Unit: - { - const Unit *u; - double fact; - u = get_unit_by_idx(v->int_value); - if (u == NULL) - fact = 0; - else - fact = unit_to_factor(u); - snprintf(buff, sizeof(buff), "%f", fact); - res = buff; -/* fprintf(stderr, "unit idx: %d %p res='%s'\n", v->int_value, u, res);*/ - } - break; - case HIDA_Mixed: - default: - fprintf(stderr, "error: hid_string2val: can't handle type %d\n", hid->type[attr_id]); - - } - if (res == NULL) - return NULL; - return strdup(res); -} - - -HID_Attr_Val hid_string2val(const hid_attr_type_t type, const char *str) -{ - HID_Attr_Val v; - memset(&v, 0, sizeof(v)); - switch(type) { - case HIDA_Boolean: - if ((strcasecmp(str, "true") == 0) || (strcasecmp(str, "yes") == 0) || (strcasecmp(str, "1") == 0)) - v.int_value = 1; - else - v.int_value = 0; - break; - case HIDA_Integer: - v.int_value = atoi(str); - break; - case HIDA_Coord: - { - char *end; - double val; - val = strtod(str, &end); - while(isspace(*end)) end++; - if (*end != '\0') { - const Unit *u; - u = get_unit_struct(end); - if (u == NULL) { - Message("Invalid unit for HIDA_Coord in the script: '%s'\n", end); - v.coord_value = 0; - } - else - v.coord_value = unit_to_coord(u, val); - } - else - v.coord_value = val; - } - break; - case HIDA_Unit: - { - const Unit *u; - u = get_unit_struct(str); - if (u != NULL) - v.real_value = unit_to_factor(u); - else - v.real_value = 0; - } - break; - case HIDA_Real: - v.real_value = atof(str); - break; - case HIDA_String: - case HIDA_Label: - case HIDA_Enum: - case HIDA_Path: - v.str_value = strdup(str); - break; - case HIDA_Mixed: - default: - fprintf(stderr, "error: hid_string2val: can't handle type %d\n", type); - } - return v; -} - -char **hid_string2enum(const char *str, HID_Attr_Val *def) -{ - char **e; - const char *s, *last; - int n, len; - - for(n=0, s=str; *s != '\0'; s++) - if (*s == '|') - n++; - e = malloc(sizeof(char *) * (n+2)); - - def->int_value = 0; - def->str_value = NULL; - def->real_value = 0.0; - - for(n = 0, last=s=str;; s++) { - - if ((*s == '|') || (*s == '\0')) { - if (*last == '*') { - def->int_value = n; - last++; - } - len = s - last; - e[n] = malloc(len+1); - if (len != 0) - strncpy(e[n], last, len); - e[n][len] = '\0'; - last = s+1; - n++; - } - if (*s == '\0') - break; - } - e[n] = NULL; - return e; -} - -int hid_add_attribute(hid_t *hid, char *attr_name, char *help, hid_attr_type_t type, int min, int max, char *default_val) -{ - int current = hid->attr_num; - - /* TODO: should realloc more space here */ - hid->attr_num++; - hid->attr = realloc(hid->attr, sizeof(HID_Attribute) * hid->attr_num); - hid->type = realloc(hid->type, sizeof(hid_attr_type_t) * hid->attr_num); - - hid->attr[current].name = strdup(attr_name); - hid->attr[current].help_text = strdup(help); - hid->attr[current].type = type; - hid->attr[current].min_val = min; - hid->attr[current].max_val = max; - if (type == HIDA_Unit) { - const Unit *u, *all; - all = get_unit_list(); - u = get_unit_struct(default_val); - if (u != NULL) - hid->attr[current].default_val.int_value = u-all; - else - hid->attr[current].default_val.int_value = -1; - } - else if (type == HIDA_Enum) { - hid->attr[current].enumerations = (const char **)hid_string2enum(default_val, &(hid->attr[current].default_val)); - } - else { - hid->attr[current].default_val = hid_string2val(type, default_val); - hid->attr[current].enumerations = NULL; - } - hid->attr[current].hash = 0; - - hid->type[current] = type; - - return current; -} - -static void cleanup_hid_reg(gpmi_module *mod, gpmi_cleanup *cl) -{ - hid_t *hid = cl->argv[0].p; - int n; - - hid_remove_hid(hid->hid); - - for(n = 0; n < hid->attr_num; n++) { - free(hid->attr[n].name); - free(hid->attr[n].help_text); - } - - if (hid->attr != NULL) - free(hid->attr); - if (hid->type != NULL) - free(hid->type); - - free((char *)hid->hid->name); - free((char *)hid->hid->description); - free(hid->hid); - free(hid); -} - -int hid_register(hid_t *hid) -{ - hid_register_hid(hid->hid); - - gpmi_mod_cleanup_insert(NULL, cleanup_hid_reg, "p", hid); - - return 0; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am (nonexistent) @@ -1,13 +0,0 @@ -# GPMI fingerprint: Makefile.am.ext-pkg - -# End INST_PATH with / -INST_PATH = pcb-gpmi/ -FILE_NAME = hid - -SOURCE = hid.c -SOURCE += hid_callbacks.c - -HEADER = hid.h -HEADER += hid_events.h -include ../../../Makefile.config -INCLUDES = -I $(PCB_SRC) Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h (nonexistent) @@ -1,21 +0,0 @@ -HID_Attribute *gpmi_hid_get_export_options(int *num); -hidGC gpmi_hid_make_gc(void); -void gpmi_hid_destroy_gc(hidGC gc); -void gpmi_hid_do_export(HID_Attr_Val * options); -void gpmi_hid_parse_arguments(int *pcbargc, char ***pcbargv); -void gpmi_hid_set_crosshair(int x, int y, int cursor_action); -int gpmi_hid_set_layer(const char *name, int group, int _empty); -void gpmi_hid_set_color(hidGC gc, const char *name); -void gpmi_hid_set_line_cap(hidGC gc, EndCapStyle style); -void gpmi_hid_set_line_width(hidGC gc, Coord width); -void gpmi_hid_set_draw_xor(hidGC gc, int xor); -void gpmi_hid_set_draw_faded(hidGC gc, int faded); -void gpmi_hid_draw_line(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); -void gpmi_hid_draw_arc(hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle); -void gpmi_hid_draw_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); -void gpmi_hid_fill_circle(hidGC gc, Coord cx, Coord cy, Coord radius); -void gpmi_hid_fill_polygon(hidGC gc, int n_coords, Coord *x, Coord *y); -void gpmi_hid_fill_pcb_polygon(hidGC gc, PolygonType *poly, const BoxType *clip_box); -void gpmi_hid_fill_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); -void gpmi_hid_fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask); -void gpmi_hid_use_mask(int use_it); Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h (nonexistent) @@ -1,86 +0,0 @@ -#include - -/* Type of an HID attribute (usually a widget on an attribute dialog box) */ -typedef enum hid_attr_type_e { - HIDA_Label, /* non-editable label displayed on the GUI */ - HIDA_Integer, /* a sugned integer value */ - HIDA_Real, /* a floating point value */ - HIDA_String, /* one line textual input */ - HIDA_Boolean, /* true/false boolean value */ - HIDA_Enum, /* select an item of a predefined list */ - HIDA_Mixed, /* TODO */ - HIDA_Path, /* path to a file or directory */ - HIDA_Unit, /* select a dimension unit */ - HIDA_Coord /* enter a coordinate */ -} hid_attr_type_t; - -gpmi_keyword *kw_hid_attr_type_e; /* of hid_attr_type_t */ - -/* TODO: these should not be here; GPMI needs to switch over to c99tree! */ -#ifndef FROM_PKG -typedef void HID; -typedef void HID_Attribute; -typedef void* hidGC; -typedef char* HID_Attr_Val; - -/* Line or arc ending style */ -typedef enum EndCapStyle_e { - Trace_Cap, /* filled circle (trace drawing) */ - Square_Cap, /* rectangular lines (square pad) */ - Round_Cap, /* round pins or round-ended pads, thermals */ - Beveled_Cap /* octagon pins or bevel-cornered pads */ -} EndCapStyle; - -typedef void *PolygonType; -typedef void *BoxType; -#endif - -typedef struct hid_s { - gpmi_module *module; - int attr_num; - HID_Attribute *attr; - hid_attr_type_t *type; - HID *hid; - HID_Attr_Val *result; - hidGC new_gc; -} hid_t; - -/* Creates a new hid context. Name and description matters only if the hid is -registered as an exporter later. */ -hid_t *hid_create(char *hid_name, char *description); - -/* Append an attribute in a hid previously created using hid_create(). - Arguments: - hid: hid_t previously created using hid_create() - attr_name: name of the attribute - help: help text for the attribute - type: type of the attribute (input widget type) - min: minimum value of the attribute, if type is integer or real) - max: maximum value of the attribute, if type is integer or real) - default_val: default value of the attribute - Returns an unique ID of the attribute the caller should store for - later reference. For example this ID is used when retrieving the - value of the attribute after the user finished entering data in - the dialog. */ -int hid_add_attribute(hid_t *hid, char *attr_name, char *help, hid_attr_type_t type, int min, int max, char *default_val); - -/* Query an attribute from the hid after dialog_attributes() returned. - Arguments: - hid: hid_t previously created using hid_create() - attr_id: the unique ID of the attribute (returned by hid_add_attribute()) - Returns the value (converted to string) set by the user. */ -dynamic char *hid_get_attribute(hid_t *hid, int attr_id); - -/* Register the hid; call it after a hid is created and its attributes - are all set up */ -int hid_register(hid_t *hid); - -/* For internal use */ -void hid_gpmi_data_set(hid_t *h, void *data); - -/* For internal use */ -hid_t *hid_gpmi_data_get(HID *h); - -/* For internal use */ -nowrap HID_Attr_Val hid_string2val(const hid_attr_type_t type, const char *str); - Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c (nonexistent) @@ -1,19 +0,0 @@ -#include - -int PKG_FUNC(init)() -{ - return 0; -} - -void PKG_FUNC(uninit)() { -} - -void PKG_FUNC(register)() { -} - -int PKG_FUNC(checkver)(int requested) { - if (requested <= 1) - return 0; - - return -1; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h (nonexistent) @@ -1,60 +0,0 @@ -/*********** Exporter events ************/ - -/* Called before get_exporter_options returns the option list to the GUI hid */ -gpmi_define_event(HIDE_get_export_options)(void *hid); - -/* Called before export redraw starts */ -gpmi_define_event(HIDE_do_export_start)(void *hid); - -/* Called after export redraw finihsed */ -gpmi_define_event(HIDE_do_export_finish)(void *hid); - -/* DRAWING */ - -/* PCB callback events for drawing: change layer */ -gpmi_define_event(HIDE_set_layer)(void *hid, const char *name, int group, int empty); - -/* PCB callback events for drawing: change drawing color */ -gpmi_define_event(HIDE_set_color)(void *hid, void *gc, const char *name); - -/* PCB callback events for drawing: change drawing line cap style*/ -gpmi_define_event(HIDE_set_line_cap)(void *hid, void *gc, EndCapStyle style); - -/* PCB callback events for drawing: change drawing line width */ -gpmi_define_event(HIDE_set_line_width)(void *hid, void *gc, int width); - -/* PCB callback events for drawing: toggle xor drawing method */ -gpmi_define_event(HIDE_set_draw_xor)(void *hid, void *gc, int xor); - -/* PCB callback events for drawing: toggle faded drawing method */ -gpmi_define_event(HIDE_set_draw_faded)(void *hid, void *gc, int faded); - -/* PCB callback events for drawing: draw a line */ -gpmi_define_event(HIDE_draw_line)(void *hid, void *gc, int x1, int y1, int x2, int y2); - -/* PCB callback events for drawing: draw an arc from center cx;cy */ -gpmi_define_event(HIDE_draw_arc)(void *hid, void *gc, int cx, int cy, int xradius, int yradius, double start_angle, double delta_angle); - -/* PCB callback events for drawing: draw a rectangle */ -gpmi_define_event(HIDE_draw_rect)(void *hid, void *gc, int x1, int y1, int x2, int y2); - -/* PCB callback events for drawing: draw a filled circle */ -gpmi_define_event(HIDE_fill_circle)(void *hid, void *gc, int cx, int cy, int radius); - -/* PCB callback events for drawing: draw a filled ploygon */ -gpmi_define_event(HIDE_fill_polygon)(void *hid, void *gc, int n_coords, int *x, int *y); - -/* PCB callback events for drawing: draw a filled rectangle */ -gpmi_define_event(HIDE_fill_rect)(void *hid, void *gc, int x1, int y1, int x2, int y2); - -/* PCB callback events for drawing: TODO */ -gpmi_define_event(HIDE_use_mask)(void *hid, int use_it); - -/* PCB callback events for drawing: create a new graphical context */ -gpmi_define_event(HIDE_make_gc)(void *hid, void *gc); - -/* PCB callback events for drawing: destroy a graphical context */ -gpmi_define_event(HIDE_destroy_gc)(void *hid, void *gc); - -/* PCB callback events for drawing: TODO */ -gpmi_define_event(HIDE_fill_pcb_pv)(void *hid, void *fg_gc, void *bg_gc, void *pad, int drawHole, int mask); Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (nonexistent) @@ -1,75 +0,0 @@ -#include -#include -#include "layout.h" -#include "src/misc.h" -#include "src/draw.h" - -#define layer_check(layer) \ - if ((layer < 0) || (layer >= MAX_LAYER+2)) \ - return - - -void layout_switch_to_layer(int layer) -{ - layer_check(layer); - ChangeGroupVisibility(layer, true, true); - Redraw(); -} - -int layout_get_current_layer() -{ - return GetLayerNumber(PCB->Data, CURRENT); -} - -int layout_resolve_layer(const char *name) -{ - int n; - if (name == NULL) - return -2; - for(n = 0; n < MAX_LAYER + 2; n++) - if ((PCB->Data->Layer[n].Name != NULL) && (strcmp(PCB->Data->Layer[n].Name, name) == 0)) - return n; - return -1; -} - -int layout_get_max_possible_layer() -{ - return MAX_LAYER+2; -} - -int layout_get_max_copper_layer() -{ - return max_copper_layer; -} - -int layout_get_max_layer() -{ - return max_copper_layer+2; -} - - -const char *layout_layer_name(int layer) -{ - layer_check(layer)(""); - return PCB->Data->Layer[layer].Name; -} - -const char *layout_layer_color(int layer) -{ - layer_check(layer)(""); - return PCB->Data->Layer[layer].Color; -} - -int layout_layer_field(int layer, layer_field_t fld) -{ - layer_check(layer)(-1); - switch(fld) { - case LFLD_NUM_LINES: return PCB->Data->Layer[layer].LineN; - case LFLD_NUM_TEXTS: return PCB->Data->Layer[layer].TextN; - case LFLD_NUM_POLYS: return PCB->Data->Layer[layer].PolygonN; - case LFLD_NUM_ARCS: return PCB->Data->Layer[layer].ArcN; - case LFLD_VISIBLE: return PCB->Data->Layer[layer].On; - case LFLD_NODRC: return PCB->Data->Layer[layer].no_drc; - } - return -1; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf (nonexistent) @@ -1,18 +0,0 @@ -@/local/headers - layout.h - -@/local/srcs - create.c layers.c object.c page.c search.c coord.c debug_draw.c draw.c - -@/local/file_name - layout - -@/local/inst_path - layout - -@/local/CFLAGS - -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### - -@@/local/hook/postall - PCB_GPMI_ROOT=../../.. - include $(PCB_GPMI_ROOT)/Makefile.config Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h (nonexistent) @@ -1,262 +0,0 @@ -#include -#include "src/global.h" -#include "src/rtree.h" -#include "src/create.h" -#include "src/data.h" - -/* Object type search mask bits */ -typedef enum layout_object_mask_e { - OM_LINE = 1, /* lines (traces, silk lines, not font) */ - OM_TEXT = 2, /* text written using the font */ - OM_POLYGON = 4, /* polygons, including rectangles */ - OM_ARC = 8, /* arcs, circles */ - OM_VIA = 16, /* vias and holes which are not part of a footprint */ - OM_PIN = 32, /* pins/pads of a footprint */ - - OM_ANY = 0xffff /* shorthand for "find anything" */ -} layout_object_mask_t; -gpmi_keyword *kw_layout_object_mask_e; /* of layout_object_mask_t */ - -/* Which coordinate of the object is referenced */ -typedef enum layout_object_coord_e { -/* X/Y coords */ - OC_BX1 = 1, /* bounding box X1 */ - OC_BX2 = 2, /* bounding box X2 */ - OC_BY1 = 3, /* bounding box Y1 */ - OC_BY2 = 4, /* bounding box Y2 */ - OC_P1X = 5, /* point 1 X */ - OC_P2X = 6, /* point 2 X */ - OC_P1Y = 7, /* point 1 Y */ - OC_P2Y = 8, /* point 2 Y */ - OC_OBJ = 9, /* the whole object */ - -/* point aliases for X/Y coords */ - OC_P1 = 5, /* point 1 is P1X*/ - OC_P2 = 6 /* point 2 is P2X */ - -} layout_object_coord_t; -gpmi_keyword *kw_layout_object_coord_e; /* of layout_object_coord_t */ - - -typedef enum layout_flag_e { - FL_NONE = 0, - FL_SHOWNUMBER = 0x00000001, - FL_LOCALREF = 0x00000002, - FL_CHECKPLANS = 0x00000004, - FL_SHOWDRC = 0x00000008, - FL_RUBBERBAND = 0x00000010, - FL_DESCRIPTION = 0x00000020, - FL_NAMEONPCB = 0x00000040, - FL_AUTODRC = 0x00000080, - FL_ALLDIRECTION = 0x00000100, - FL_SWAPSTARTDIR = 0x00000200, - FL_UNIQUENAME = 0x00000400, - FL_CLEARNEW = 0x00000800, - FL_SNAPPIN = 0x00001000, - FL_SHOWMASK = 0x00002000, - FL_THINDRAW = 0x00004000, - FL_ORTHOMOVE = 0x00008000, - FL_LIVEROUTE = 0x00010000, - FL_THINDRAWPOLY = 0x00020000, - FL_LOCKNAMES = 0x00040000, - FL_ONLYNAMES = 0x00080000, - FL_NEWFULLPOLY = 0x00100000, - FL_HIDENAMES = 0x00200000, - - FL_THERMALSTYLE1 = 0x08000000, - FL_THERMALSTYLE2 = 0x10000000, - FL_THERMALSTYLE3 = 0x20000000, - FL_THERMALSTYLE4 = 0x40000000, - FL_THERMALSTYLE5 = 0x80000000 -} layout_flag_t; -gpmi_keyword *kw_layout_flag_e; /* of layout_flag_t */ - - - -typedef struct layout_object_s { - layout_object_mask_t type; - union { - LineType *l; - TextType *t; - PolygonType *p; - ArcType *a; - PinType *v; - PinType *pin; - } obj; - int layer; -} layout_object_t; - - -typedef struct layout_search_s { - layout_object_mask_t searching; /* during the search, this field is used to communicate with the callback */ - int used, alloced; - layout_object_t *objects; - int layer; -} layout_search_t; - -/* -- search -- (search.c) */ -/* creates a new search and adds all objects that matches obj_types mask within the given rectangle on the current layer - Arguments: - search_ID: unique name of the search (overwrites existing search on the same name) - obj_types: on or more object types - x1, y1, x2, y2: box the search is done within (PCB coords) - Returns the number of object on the search list. */ -int layout_search_box(const char *search_ID, layout_object_mask_t obj_types, int x1, int y1, int x2, int y2); - -/* creates a new search and adds all selected objects - Arguments: - search_ID: unique name of the search (overwrites existing search on the same name) - obj_types: on or more object types - Returns the number of object on the search list. */ -int layout_search_selected(const char *search_ID, multiple layout_object_mask_t obj_types); - -/* creates a new search and adds all found objects (the green highlight) - Arguments: - search_ID: unique name of the search (overwrites existing search on the same name) - obj_types: on or more object types - Returns the number of object on the search list. */ -int layout_search_found(const char *search_ID, multiple layout_object_mask_t obj_types); - -/* Returns the nth object from a search list (or NULL pointer if n is beyond the list) */ -layout_object_t *layout_search_get(const char *search_ID, int n); - -/* Frees all memory related to a search. Returns 0 on success. - Argument: - search_ID: unique name of the search (requires an existing search) */ -int layout_search_free(const char *search_ID); - -/* -- object accessors -- (object.c) */ -/* Return the requested coord of an object; except for the bounding box - coordinates, the meaning of coordinates are object-specific. - Point 1 and point 2 are usually endpoints of the object (line, arc), - "the whole object" coordinate is a central point. */ -int layout_obj_coord(layout_object_t *obj, layout_object_coord_t coord); - -/* Return the type of an object (always a single bit) */ -layout_object_mask_t layout_obj_type(layout_object_t *obj); - -/* Change location of an object or parts of the object (like move endpoint of a line); - Arguments: - obj: the object - coord: which coordinate to drag (e.g. move only the endpoint) - dx, dy: relative x and y coordinates the selected coordinate is displaced by - Returns 0 on success */ -int layout_obj_move(layout_object_t *obj, layout_object_coord_t coord, int dx, int dy); - -/* change angles of an arc; start and delate are relative if relative is non-zero; returns 0 on success */ -int layout_arc_angles(layout_object_t *obj, int relative, int start, int delta); - -/* -- create new objects -- (create.c) */ -/* create a line */ -int layout_create_line(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags); - -/* same as layout_create_line(), but appends the result to a list and - returns the index of the new object on the list (can be used as n for - layour_search_get) -int layout_lcreate_line(const char *search_ID, int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags);*/ - -/* create a named via */ -int layout_create_via(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags); - -/* create a new arc; sa is start angle, dir is delta angle */ -int layout_create_arc(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags); - -/* -- layer manipulation -- (layers.c) */ -/* Field name of the layer structure */ -typedef enum layer_field_e { - LFLD_NUM_LINES, /* number of lines on the layer */ - LFLD_NUM_TEXTS, /* number of texts on the layer */ - LFLD_NUM_POLYS, /* number of polygons on the layer */ - LFLD_NUM_ARCS, /* number of arcs on the layer */ - LFLD_VISIBLE, /* non-zero if the layer is visible */ - LFLD_NODRC /* non-zero if the layer doesn't use DRC */ -} layer_field_t; - -/* switch to layer (further layer-specific actions will take place there) */ -void layout_switch_to_layer(int layer); - -/* returns the number of the current layer */ -int layout_get_current_layer(); - -/* resolve layer number by name (case sensitive); returns negative number if not found */ -int layout_resolve_layer(const char *name); - -/* return the theoretical number of layers supported by PCB */ -int layout_get_max_possible_layer(); - -/* return the actual number of copper layers on the current design */ -int layout_get_max_copper_layer(); - -/* return the actual number of layers on the current design */ -int layout_get_max_layer(); - -/* return the name of a layer */ -const char *layout_layer_name(int layer); - -/* return the color of a layer */ -const char *layout_layer_color(int layer); - -/* return an integer field of a layer */ -int layout_layer_field(int layer, layer_field_t fld); - - -/* -- page manipulation -- (page.c) */ -/* query or set width and height of the drawing */ -int layout_get_page_width(); -int layout_get_page_height(); -void layout_set_page_size(int width, int height); - -/* -- coordinate system -- (coord.c) */ -double mil2pcb_multiplier(); -double mm2pcb_multiplier(); -const char *current_grid_unit(); - -typedef struct dctx_s { - void *hid; - void *gc; -} dctx_t; - -/* -- debug draw GC -- */ -/* Initialize debug drawing; returns 1 if worked, 0 if denied */ -int debug_draw_request(void); - -/* Flush the drawing */ -void debug_draw_flush(void); - -/* Finish (close) drawing */ -void debug_draw_finish(dctx_t *ctx); - -/* Get the draw context of debug draw */ -dctx_t *debug_draw_dctx(void); - -/* -- draw on a GC -- */ - -/* Debug draw style: set drawing color */ -void draw_set_color(dctx_t *ctx, const char *name); -/*void set_line_cap(dctx_t *ctx, EndCapStyle style_);*/ - -/* Debug draw style: set line width */ -void draw_set_line_width(dctx_t *ctx, int width); - -/* Debug draw style: set whether drawing should happen in xor */ -void draw_set_draw_xor(dctx_t *ctx, int xor); - -/* Debug draw style: set whether drawing should happen in faded mode */ -void draw_set_draw_faded(dctx_t *ctx, int faded); - -/* Debug draw: draw a line using the current style settings */ -void draw_line(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); - -/* -void draw_arc(dctx_t *ctx, int cx_, int cy_, int xradius_, int yradius_, double start_angle_, double delta_angle_); -void draw_rect(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); -void fill_circle(dctx_t *ctx, int cx_, int cy_, int radius_); -void fill_polygon(dctx_t *ctx, int n_ints_, int *x_, int *y_); -void fill_pcb_polygon(dctx_t *ctx, PolygonType *poly, const BoxType *clip_box); -void thindraw_pcb_polygon(dctx_t *ctx, PolygonType *poly, const BoxType *clip_box); -void fill_pcb_pad(dctx_t *ctx, PadType *pad, bool clip, bool mask); -void thindraw_pcb_pad(dctx_t *ctx, PadType *pad, bool clip, bool mask); -void fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); -void thindraw_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); -void fill_rect(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); -*/ Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c (nonexistent) @@ -1,112 +0,0 @@ -#include -#include -#include "layout.h" -#include "src/undo.h" - - -typedef struct flag_tr_s { - int flag; /* flag or thermal */ - int gpmi, pcb; -} flag_tr_t; - -static flag_tr_t flags[] = { - {1, FL_SHOWNUMBER, SHOWNUMBERFLAG}, - {1, FL_LOCALREF, LOCALREFFLAG}, - {1, FL_CHECKPLANS, CHECKPLANESFLAG}, - {1, FL_SHOWDRC, SHOWDRCFLAG}, - {1, FL_RUBBERBAND, RUBBERBANDFLAG}, - {1, FL_DESCRIPTION, DESCRIPTIONFLAG}, - {1, FL_NAMEONPCB, NAMEONPCBFLAG}, - {1, FL_AUTODRC, AUTODRCFLAG}, - {1, FL_ALLDIRECTION, ALLDIRECTIONFLAG}, - {1, FL_SWAPSTARTDIR, SWAPSTARTDIRFLAG}, - {1, FL_UNIQUENAME, UNIQUENAMEFLAG}, - {1, FL_CLEARNEW, CLEARNEWFLAG}, - {1, FL_SNAPPIN, SNAPPINFLAG}, - {1, FL_SHOWMASK, SHOWMASKFLAG}, - {1, FL_THINDRAW, THINDRAWFLAG}, - {1, FL_ORTHOMOVE, ORTHOMOVEFLAG}, - {1, FL_LIVEROUTE, LIVEROUTEFLAG}, - {1, FL_THINDRAWPOLY, THINDRAWPOLYFLAG}, - {1, FL_LOCKNAMES, LOCKNAMESFLAG}, - {1, FL_ONLYNAMES, ONLYNAMESFLAG}, - {1, FL_NEWFULLPOLY, NEWFULLPOLYFLAG}, - {1, FL_HIDENAMES, HIDENAMESFLAG}, - - {0, FL_THERMALSTYLE1, 1}, - {0, FL_THERMALSTYLE2, 2}, - {0, FL_THERMALSTYLE3, 3}, - {0, FL_THERMALSTYLE4, 4}, - {0, FL_THERMALSTYLE5, 5}, - {0, 0, 0} -}; - -static FlagType get_flags(int in) -{ - flag_tr_t *f; - static FlagType out; - - out.f = 0; - memset(out.t, 0, sizeof(out.t)); - for(f = flags; f->gpmi != 0; f++) { - if (in & f->gpmi) { - if (f->flag) - out.f |= f->pcb; - else - memset(out.t, f->pcb, sizeof(out.t)); - } - } - return out; -} - -static void *layout_create_line_(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags) -{ - void *line; - - line = CreateNewLineOnLayer (CURRENT, x1, y1, x2, y2, thickness, clearance, get_flags(flags)); - if (line != NULL) { - AddObjectToCreateUndoList (LINE_TYPE, CURRENT, line, line); - return line; - } - return NULL; -} - -int layout_create_line(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags) -{ - return layout_create_line_(x1, y1, x2, y2, thickness, clearance, flags) != NULL; -} - -static void *layout_create_via_(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags) -{ - void *pin; - - pin = CreateNewVia (PCB->Data, x, y, thickness, clearance, mask, hole, name, get_flags(flags)); - - if (pin != NULL) { - AddObjectToCreateUndoList (VIA_TYPE, pin, pin, pin); - return pin; - } - return NULL; -} - -int layout_create_via(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags) -{ - return layout_create_via_(x, y, thickness, clearance, mask, hole, name, flags) != NULL; -} - -static void *layout_create_arc_(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags) -{ - void *arc; - arc = CreateNewArcOnLayer (CURRENT, x, y, width, height, sa, dir, thickness, clearance, get_flags(flags)); - if (arc != NULL) { - AddObjectToCreateUndoList (ARC_TYPE, CURRENT, arc, arc); - return 0; - } - return NULL; -} - -int layout_create_arc(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags) -{ - return layout_create_arc_(x, y, width, height, sa, dir, thickness, clearance, flags) != NULL; -} - Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c (nonexistent) @@ -1,49 +0,0 @@ -#include -#include -#include "layout.h" -#include "src/hid.h" -#include "src/error.h" - -static HID *ddh = NULL; - -#define need_ddh if (ddh == NULL) return - - -int debug_draw_request(void) -{ - ddh = gui->request_debug_draw(); - if (ddh == NULL) - return 0; - return 1; -} - -void debug_draw_flush(void) -{ - need_ddh; - gui->flush_debug_draw(); -} - -void debug_draw_finish(dctx_t *ctx) -{ - need_ddh; - ddh->destroy_gc(ctx->gc); - gui->finish_debug_draw(); - free(ctx); - ddh = NULL; -} - -dctx_t *debug_draw_dctx(void) -{ - dctx_t *ctx; - hidGC gc; - need_ddh(NULL); - gc = ddh->make_gc(); - if (gc == NULL) { - Message("debug_draw_dctx(): failed to make a new gc on ddh %p\n", ddh); - return NULL; - } - - ctx = malloc(sizeof(dctx_t)); - ctx->hid = ddh; - ctx->gc = gc; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep (nonexistent) @@ -1 +0,0 @@ -#Please run make depend! Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (nonexistent) @@ -1,183 +0,0 @@ -#include -#include -#include -#include -#include "layout.h" -#include "config.h" - -static inline void search_append(layout_search_t *s, void *obj) -{ - layout_object_t *o; - if (s->used >= s->alloced) { - s->alloced += 256; - s->objects = realloc(s->objects, s->alloced * sizeof(layout_object_t)); - } - o = s->objects + s->used; - s->used++; - o->type = s->searching; - o->layer = s->layer; - switch(s->searching) { - case OM_LINE: o->obj.l = obj; break; - case OM_TEXT: o->obj.t = obj; break; - case OM_POLYGON: o->obj.p = obj; break; - case OM_ARC: o->obj.a = obj; break; - case OM_VIA: o->obj.v = obj; break; - case OM_PIN: o->obj.pin = obj; break; - default: - assert(!"Unimplemented object type"); - } -} - -static int search_callback (const BoxType * b, void *cl) -{ - search_append(cl, (void *)b); - return 1; -} - -hash_t *layout_searches = NULL; -static layout_search_t *new_search(const char *search_ID) -{ - layout_search_t *s; - layout_search_free(search_ID); - - if (layout_searches == NULL) { - layout_searches = hash_create(64, gpmi_hash_ptr); - assert(layout_searches != NULL); - } - - s = calloc(sizeof(layout_search_t), 1); - - hash_store(layout_searches, search_ID, s); - return s; -} - -int layout_search_box(const char *search_ID, layout_object_mask_t obj_types, int x1, int y1, int x2, int y2) -{ - BoxType spot; - layout_search_t *s = new_search(search_ID); - - spot.X1 = x1; - spot.Y1 = y1; - spot.X2 = x2; - spot.Y2 = y2; - - s->layer = -1; - if (obj_types & OM_LINE) { - s->searching = OM_LINE; - r_search (CURRENT->line_tree, &spot, NULL, search_callback, s); - } - - if (obj_types & OM_TEXT) { - s->searching = OM_TEXT; - r_search (CURRENT->text_tree, &spot, NULL, search_callback, s); - } - - if (obj_types & OM_ARC) { - s->searching = OM_ARC; - r_search (CURRENT->arc_tree, &spot, NULL, search_callback, s); - } - - if (obj_types & OM_VIA) { - s->searching = OM_VIA; - r_search (PCB->Data->via_tree, &spot, NULL, search_callback, s); - } - - if (obj_types & OM_PIN) { - s->searching = OM_PIN; - r_search (PCB->Data->pin_tree, &spot, NULL, search_callback, s); - } - - if (obj_types & OM_POLYGON) { - s->searching = OM_POLYGON; - for (s->layer = 0; s->layer < MAX_LAYER + 2; s->layer++) - r_search (PCB->Data->Layer[s->layer].polygon_tree, &spot, NULL, search_callback, s); - s->layer = -1; - } - - return s->used; -} - -/* SELECTEDFLAG */ - -typedef struct { - int flag; - layout_search_t *search; -} select_t; - -static void select_cb(void *obj_, void *ud) -{ - select_t *ctx = ud; - AnyObjectTypePtr obj = obj_; - if (TEST_FLAG(ctx->flag, obj)) - search_append(ctx->search, obj); -} - -#define select(s, om, flag, lst) \ - do { \ - select_t ctx; \ - ctx.flag = flag; \ - ctx.search = s; \ - s->searching = om; \ - g_list_foreach(lst, select_cb, &ctx); \ - s->searching = 0; \ - } while(0) - -static int layout_search_flag(const char *search_ID, multiple layout_object_mask_t obj_types, int flag) -{ - Cardinal l, n; - layout_search_t *s = new_search(search_ID); - LayerType *layer = PCB->Data->Layer; - - for (l =0; l < MAX_LAYER + 2; l++, layer++) { - s->layer = l; - select(s, OM_ARC, flag, layer->Arc); - select(s, OM_LINE, flag, layer->Line); - select(s, OM_TEXT, flag, layer->Text); - select(s, OM_POLYGON, flag, layer->Polygon); - } - select(s, OM_VIA, flag, PCB->Data->Via); -/* select(s, OM_PIN, flag, PCB->Data->Pin, PCB->Data->PinN); /* TODO */ - - return s->used; -} -#undef select - -int layout_search_selected(const char *search_ID, multiple layout_object_mask_t obj_types) -{ - return layout_search_flag(search_ID, obj_types, SELECTEDFLAG); -} - -int layout_search_found(const char *search_ID, multiple layout_object_mask_t obj_types) -{ - return layout_search_flag(search_ID, obj_types, FOUNDFLAG); -} - -layout_object_t *layout_search_get(const char *search_ID, int n) -{ - const layout_search_t *s; - - s = hash_find(layout_searches, search_ID); - -/* printf("s=%p\n", s);*/ - if ((s == NULL) || (n < 0) || (n >= s->used)) - return NULL; - return s->objects+n; -} - -int layout_search_free(const char *search_ID) -{ - layout_search_t *s; - - if (layout_searches == NULL) - return 1; - - s = (layout_search_t *)hash_find(layout_searches, search_ID); - if (s != NULL) { - hash_del_key(layout_searches, search_ID); - free(s->objects); - free(s); - return 0; - } - return 2; -} - Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c (nonexistent) @@ -1,143 +0,0 @@ -#include -#include -#include "layout.h" -#include "src/change.h" -#include "src/misc.h" -#include "src/move.h" - -int layout_obj_coord(layout_object_t *obj, layout_object_coord_t coord) -{ - AnyObjectType *o; - - if (obj == NULL) - return -1; - - o = (AnyObjectType *)obj->obj.l; - - /* bounding box is the same for any type */ - switch (coord) { - case OC_BX1: return o->BoundingBox.X1; - case OC_BX2: return o->BoundingBox.X2; - case OC_BY1: return o->BoundingBox.Y1; - case OC_BY2: return o->BoundingBox.Y2; - case OC_OBJ: return -1; - default: /* avoids warnings for unhandled requests we handle later, per object type */ - ; - } - - switch(obj->type) { - case OM_LINE: - switch (coord) { - case OC_P1X: return obj->obj.l->Point1.X; - case OC_P2X: return obj->obj.l->Point2.X; - case OC_P1Y: return obj->obj.l->Point1.Y; - case OC_P2Y: return obj->obj.l->Point2.Y; - default: /* avoids warnings for unhandled requests we handled above */ - ; - } - break; - case OM_TEXT: - switch (coord) { - case OC_P1X: - case OC_P2X: return obj->obj.t->X; - case OC_P1Y: - case OC_P2Y: return obj->obj.t->Y; - default: /* avoids warnings for unhandled requests we handled above */ - ; - } - break; - case OM_VIA: - switch (coord) { - case OC_P1X: - case OC_P2X: return obj->obj.v->X; - case OC_P1Y: - case OC_P2Y: return obj->obj.v->Y; - default: /* avoids warnings for unhandled requests we handled above */ - ; - } - break; - case OM_PIN: - switch (coord) { - case OC_P1X: - case OC_P2X: return obj->obj.pin->X; - case OC_P1Y: - case OC_P2Y: return obj->obj.pin->Y; - default: /* avoids warnings for unhandled requests we handled above */ - ; - } - break; - } - - return -1; -} - -layout_object_mask_t layout_obj_type(layout_object_t *obj) -{ - if (obj == NULL) - return 0; - return obj->type; -} - -int layout_obj_move(layout_object_t *obj, layout_object_coord_t coord, int dx, int dy) -{ - void *what = NULL;; - - if (obj == NULL) - return -1; - - switch(obj->type) { - case OM_LINE: - switch(coord) { - case OC_OBJ: - MoveObject (LINEPOINT_TYPE, CURRENT, obj->obj.l, &(obj->obj.l->Point2), dx, dy); - /* intended falltrough */ - case OC_P1X: - case OC_P1Y: what = &(obj->obj.l->Point1); break; - case OC_P2X: - case OC_P2Y: what = &(obj->obj.l->Point2); break; - default: /* we do not handle anything else for now */ - ; - } - MoveObject (LINEPOINT_TYPE, CURRENT, obj->obj.l, what, dx, dy); - return 0; - case OM_TEXT: - MoveObject (TEXT_TYPE, CURRENT, obj->obj.t, obj->obj.t, dx, dy); - return 0; - case OM_VIA: - MoveObject (VIA_TYPE, obj->obj.v, obj->obj.v, obj->obj.v, dx, dy); - return 0; - case OM_PIN: - MoveObject (PIN_TYPE, obj->obj.pin, obj->obj.pin, obj->obj.pin, dx, dy); - return 0; - case OM_ARC: - switch(coord) { - case OC_OBJ: - MoveObject (ARC_TYPE, CURRENT, obj->obj.a, obj->obj.a, dx, dy); - return 0; - default: /* we do not handle anything else for now */ - ; - } - /*TODO: move endpoints! */ - break; - case OM_POLYGON: - if (obj->layer != -1) { - MoveObject (POLYGON_TYPE, PCB->Data->Layer + obj->layer, obj->obj.p, obj->obj.p, dx, dy); - return 0; - } - } - return -1; -} - -int layout_arc_angles(layout_object_t *obj, int relative, int start, int delta) -{ - if (obj == NULL) - return -1; - if (obj->type != OM_ARC) - return 1; - if (relative) { - start += obj->obj.a->StartAngle; - delta += obj->obj.a->Delta; - } - ChangeArcAngles (CURRENT, obj->obj.a, start, delta); - return 0; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c (nonexistent) @@ -1,20 +0,0 @@ -#include "layout.h" -#include "src/pcb-printf.h" - -double mil2pcb_multiplier() -{ - return 10000.0*2.54; -} - -double mm2pcb_multiplier() -{ - return 1000000.0; -} - -const char *current_grid_unit() -{ - const Unit *u = Settings.grid_unit; - if (u == NULL) - return ""; - return u->suffix; -} Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am (nonexistent) @@ -1,20 +0,0 @@ -# This file is package-specific. Do include it in the distribution. -# -# GPMI fingerprint: Makefile.am.ext-pkg - -# End INST_PATH with / -INST_PATH = pcb-gpmi/ -FILE_NAME = layout - -SOURCE = search.c -SOURCE += object.c -SOURCE += create.c -SOURCE += layers.c -SOURCE += page.c - -HEADER = layout.h - -PKG_LDFLAGS = - -include ../../../Makefile.config -INCLUDES = -I $(PCB_SRC) Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c (nonexistent) @@ -1,18 +0,0 @@ -#include "layout.h" -#include "src/change.h" - -int layout_get_page_width() -{ - return PCB->MaxWidth; -} - -int layout_get_page_height() -{ - return PCB->MaxHeight; -} - -void layout_set_page_size(int width, int height) -{ - ChangePCBSize (MIN(MAX_COORD, MAX(width, MIN_SIZE)), MIN(MAX_COORD, MAX(height, MIN_SIZE))); -} - Index: src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c =================================================================== --- src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c (nonexistent) @@ -1,45 +0,0 @@ -#include -#include -#include "layout.h" -#include "src/hid.h" -#include "src/error.h" - -#define setup \ - hidGC gc = ctx->gc; \ - HID *hid = ctx->hid; \ - if ((hid == NULL) && (gc == NULL)) Message("%s failed because of invalid hid or gc\n", __FUNCTION__); \ - if ((hid == NULL) && (gc == NULL)) return - - -void draw_set_color(dctx_t *ctx, const char *name) -{ - setup; - hid->set_color(gc, name); -} - -/*void set_line_cap(dctx_t *ctx, EndCapStyle style_);*/ -void draw_set_line_width(dctx_t *ctx, int width) -{ - setup; - hid->set_line_width(gc, width); -} - -void draw_set_draw_xor(dctx_t *ctx, int xor) -{ - setup; - hid->set_draw_xor(gc, xor); -} - - -void draw_set_draw_faded(dctx_t *ctx, int faded) -{ - setup; - hid->set_draw_faded(gc, faded); -} - -void draw_line(dctx_t *ctx, int x1, int y1, int x2, int y2) -{ - setup; - hid->draw_line(gc, x1, y1, x2, y2); -} - Index: src/pcb-gpmi/gpmi_plugin/scripts.h =================================================================== --- src/pcb-gpmi/gpmi_plugin/scripts.h (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/scripts.h (nonexistent) @@ -1,39 +0,0 @@ -typedef struct hid_gpmi_script_info_s hid_gpmi_script_info_t; - -struct hid_gpmi_script_info_s { - char *name; - char *module_name; - char *conffile_name; - gpmi_module *module; - - hid_gpmi_script_info_t *next; -}; - -extern hid_gpmi_script_info_t *hid_gpmi_script_info; - -/* Load a GPMI module; if i is NULL, allocate a new slot on the list, else unload - i first and place the new module in place of i. */ -hid_gpmi_script_info_t *hid_gpmi_load_module(hid_gpmi_script_info_t *i, const char *module_name, const char *params, const char *config_file_name); - -/* Reload a script - useful if the source of the script has changed - Reloads a module already loaded; return NULL on error. */ -hid_gpmi_script_info_t *hid_gpmi_reload_module(hid_gpmi_script_info_t *i); - -/* look up a module by name - slow linear search */ -hid_gpmi_script_info_t *hid_gpmi_lookup(const char *name); - -void hid_gpmi_load_dir(const char *dir, int add_pkg_path); -char *gpmi_hid_asm_scriptname(const void *info, const char *file_name); - -/* Return the number of scripts (gpmi modules) loaded */ -int gpmi_hid_scripts_count(); - -/* Unload a script (also removes i from the list) - temporary effect, - the script will be loaded again on the next startup */ -int gpmi_hid_script_unload(hid_gpmi_script_info_t *i); - -/* Remove a script from the config file (but do not unload it now) */ -int gpmi_hid_script_remove(hid_gpmi_script_info_t *i); - -/* Edit a config file so that the script is in it */ -int gpmi_hid_script_addcfg(hid_gpmi_script_info_t *i); Index: src/pcb-gpmi/gpmi_plugin/Makefile =================================================================== --- src/pcb-gpmi/gpmi_plugin/Makefile (revision 1067) +++ src/pcb-gpmi/gpmi_plugin/Makefile (nonexistent) @@ -1,37 +0,0 @@ -PCB_GPMI_ROOT=.. -include Makefile.gpmi -include $(PCB_GPMI_ROOT)/Makefile.config - -CFLAGS += -Wall -g -I$(PCB_SRC) $(PCB_CFLAGS) - -COMMON_OBJS = scripts.o manage_scripts.o -BUILDIN_OBJS = gpmi_buildin.o $(COMMON_OBJS) -PLUGIN_OBJS = gpmi_plugin.o $(COMMON_OBJS) - -all: gpmi_plugin.so gpmi_buildin.a - cd gpmi_pkg; make - -all_plugin: gpmi_plugin.so - cd gpmi_pkg; make - -all_buildin: gpmi_buildin.a - cd gpmi_pkg; make - -gpmi_buildin.a: $(BUILDIN_OBJS) - ar rvu gpmi_buildin.a $(BUILDIN_OBJS) - -gpmi_plugin.so: $(PLUGIN_OBJS) - $(CC) $(LDFLAGS) -shared -rdynamic -o gpmi_plugin.so $(PLUGIN_OBJS) $(PCB_LDFLAGS) - -gpmi_plugin.o: gpmi_plugin.c scripts.h - -gpmi_buildin.o: gpmi_plugin.c scripts.h - $(CC) -DPLUGIN_INIT_NAME=hid_gpmi_init $(CFLAGS) -c gpmi_plugin.c -o gpmi_buildin.o - -scripts.o: scripts.c - -manage_scripts.o: manage_scripts.c - -clean: - rm gpmi_plugin.o gpmi_plugin.so gpmi_buildin.a gpmi_buildin.o $(COMMON_OBJS) 2>/dev/null ; true - cd gpmi_pkg; make clean Index: src/pcb-gpmi/Makefile =================================================================== --- src/pcb-gpmi/Makefile (revision 1067) +++ src/pcb-gpmi/Makefile (nonexistent) @@ -1,26 +0,0 @@ -PCB_GPMI_ROOT=. - -all: - cd gpmi_plugin; make all - -include ../../Makefile.conf -PLUGIN_DIR=$(LIBDIR)/plugins - -clean: - cd gpmi_plugin; make clean - -test: all - cd host_lib; ./test.sh - - -# TODO: temporary code until gpmi-config is fixed to generate install rules -install: - -mkdir -p $(PLUGIN_DIR)/pcb-rnd-gpmi/ - -cp gpmi_plugin/gpmi_plugin.so $(PLUGIN_DIR)/gpmi_plugin.so - cp `ls gpmi_plugin/gpmi_pkg/*.h gpmi_plugin/gpmi_pkg/*.so` $(PLUGIN_DIR)/pcb-rnd-gpmi/ - -linstall: - -mkdir -p $(PLUGIN_DIR)/pcb-rnd-gpmi/ - -ln -sf "`pwd`/gpmi_plugin/gpmi_plugin.so" "$(PLUGIN_DIR)/gpmi_plugin.so" - -for n in `ls gpmi_plugin/gpmi_pkg/*.h gpmi_plugin/gpmi_pkg/*.so`; do ln -sf "`pwd`/$$n" "$(PLUGIN_DIR)/pcb-rnd-gpmi/`basename $$n`"; done - Index: src/Makefile.in =================================================================== --- src/Makefile.in (revision 1067) +++ src/Makefile.in (revision 1068) @@ -127,14 +127,8 @@ include {../src_plugins/edif/Makefile.mod} include {../src_plugins/djopt/Makefile.mod} include {../src_plugins/mincut/Makefile.mod} +include {../src_plugins/gpmi/Makefile.mod} - -if /target/libs/script/gpmi/presents then -include {Makefile.in.mod/gpmi_plugin} -end - - - append /local/pcb/CFLAGS /target/libs/sul/glib/cflags append /local/pcb/LIBS /target/libs/sul/glib/ldflags @@ -156,8 +150,8 @@ # *** DO NOT EDIT THIS FILE *** # This file has been generated from Makefile.in by configure # *** DO NOT EDIT THIS FILE *** - PLUGDIR=../src_plugins +@/local/pcb/TOPVARS@ OBJS=@/local/pcb/OBJS@ SRCS=@/local/pcb/SRCS@ CFLAGS=@/local/pcb/CFLAGS@ Index: src/Makefile.in.mod/gpmi_plugin =================================================================== --- src/Makefile.in.mod/gpmi_plugin (revision 1067) +++ src/Makefile.in.mod/gpmi_plugin (nonexistent) @@ -1,47 +0,0 @@ -append /local/pcb/CLEANRULES {clean_gpmi} - -append /local/pcb/RULES [@ -### gpmi_plugin -clean_gpmi: FORCE - cd pcb-gpmi && make clean -@] - - -append /local/pcb/rules/install { cd pcb-gpmi && make install} { -} -append /local/pcb/rules/linstall { cd pcb-gpmi && make linstall} { -} -append /local/pcb/rules/uninstall { cd pcb-gpmi && make uninstall} { -} - -if /local/pcb/gpmi/buildin then - -append /local/pcb/LIBS {pcb-gpmi/gpmi_plugin/gpmi_buildin.a} -append /local/pcb/EXEDEPS {pcb-gpmi/gpmi_plugin/gpmi_buildin.a} -append /local/pcb/LDFLAGS /target/libs/script/gpmi/ldflags - -append /local/pcb/buildin_init { extern void hid_gpmi_init(); hid_gpmi_init(); plugin_register("gpmi", "", NULL, 0); } - -#append /local/pcb/CFLAGS /target/libs/script/gpmi/cflags -#append /local/pcb/LDFLAGS /target/libs/script/gpmi/ldflags -#append /local/pcb/LIBS /target/libs/script/gpmi/libs - -append /local/pcb/RULES [@ - -pcb-gpmi/gpmi_plugin/gpmi_buildin.a: FORCE - cd pcb-gpmi/gpmi_plugin && make all_buildin - -@] - -else - -append /local/pcb/all {pcb-gpmi/gpmi_plugin/gpmi_plugin.o} - -append /local/pcb/RULES [@ - -pcb-gpmi/gpmi_plugin/gpmi_plugin.o: FORCE - cd pcb-gpmi/gpmi_plugin && make all_plugin - -@] - -end Index: src_plugins/gpmi/Makefile =================================================================== --- src_plugins/gpmi/Makefile (nonexistent) +++ src_plugins/gpmi/Makefile (revision 1068) @@ -0,0 +1,4 @@ +all: + cd ../../src && make mod_pcb_gpmi + + Index: src_plugins/gpmi/Makefile.mod =================================================================== --- src_plugins/gpmi/Makefile.mod (nonexistent) +++ src_plugins/gpmi/Makefile.mod (revision 1068) @@ -0,0 +1,66 @@ +append /local/pcb/pcb_gpmi/enable {} +append /local/pcb/pcb_gpmi/buildin {} + +append /local/pcb/CLEANRULES {clean_gpmi} + +append /local/pcb/TOPVARS [@ +PCB_GPMI=${PLUGDIR}/gpmi/pcb-gpmi +@] + +append /local/pcb/RULES [@ +### gpmi_plugin +clean_gpmi: FORCE + cd $(PCB_GPMI) && make clean +@] + + +append /local/pcb/rules/install { cd $(PCB_GPMI) && make install} { +} +append /local/pcb/rules/linstall { cd $(PCB_GPMI) && make linstall} { +} +append /local/pcb/rules/uninstall { cd $(PCB_GPMI) && make uninstall} { +} + + +if /target/libs/script/gpmi/presents then + if /local/pcb/gpmi/buildin then + append /local/pcb/RULES [@ + +mod_pcb_gpmi: all + +@] + + append /local/pcb/LIBS {$(PCB_GPMI)/gpmi_plugin/gpmi_buildin.a} + append /local/pcb/EXEDEPS {$(PCB_GPMI)/gpmi_plugin/gpmi_buildin.a} + append /local/pcb/LDFLAGS /target/libs/script/gpmi/ldflags + + append /local/pcb/buildin_init { extern void hid_gpmi_init(); hid_gpmi_init(); plugin_register("gpmi", "", NULL, 0); } + +# append /local/pcb/CFLAGS /target/libs/script/gpmi/cflags +# append /local/pcb/LDFLAGS /target/libs/script/gpmi/ldflags +# append /local/pcb/LIBS /target/libs/script/gpmi/libs + + append /local/pcb/RULES [@ + +$(PCB_GPMI)/gpmi_plugin/gpmi_buildin.a: FORCE + cd $(PCB_GPMI)/gpmi_plugin && make all_buildin + +@] + + else + append /local/pcb/all [@ $(PCB_GPMI)/gpmi_plugin/pcb_gpmi.so @] + append /local/pcb/RULES [@ + +mod_pcb_gpmi: $(PCB_GPMI)/gpmi_plugin/pcb_gpmi.so + +@] + + append /local/pcb/RULES [@ + +$(PCB_GPMI)/gpmi_plugin/pcb_gpmi.so: FORCE + cd $(PCB_GPMI)/gpmi_plugin && make all_plugin + +@] + + end +end Index: src_plugins/gpmi/pcb-gpmi/Makefile =================================================================== --- src_plugins/gpmi/pcb-gpmi/Makefile (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/Makefile (revision 1068) @@ -0,0 +1,26 @@ +PCB_GPMI_ROOT=. + +all: + cd gpmi_plugin; make all + +include ../../../Makefile.conf +PLUGIN_DIR=$(LIBDIR)/plugins + +clean: + cd gpmi_plugin; make clean + +test: all + cd host_lib; ./test.sh + + +# TODO: temporary code until gpmi-config is fixed to generate install rules +install: + -mkdir -p $(PLUGIN_DIR)/pcb-rnd-gpmi/ + -cp gpmi_plugin/gpmi_plugin.so $(PLUGIN_DIR)/gpmi_plugin.so + cp `ls gpmi_plugin/gpmi_pkg/*.h gpmi_plugin/gpmi_pkg/*.so` $(PLUGIN_DIR)/pcb-rnd-gpmi/ + +linstall: + -mkdir -p $(PLUGIN_DIR)/pcb-rnd-gpmi/ + -ln -sf "`pwd`/gpmi_plugin/gpmi_plugin.so" "$(PLUGIN_DIR)/gpmi_plugin.so" + -for n in `ls gpmi_plugin/gpmi_pkg/*.h gpmi_plugin/gpmi_pkg/*.so`; do ln -sf "`pwd`/$$n" "$(PLUGIN_DIR)/pcb-rnd-gpmi/`basename $$n`"; done + Index: src_plugins/gpmi/pcb-gpmi/Makefile.config.in =================================================================== --- src_plugins/gpmi/pcb-gpmi/Makefile.config.in (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/Makefile.config.in (revision 1068) @@ -0,0 +1,15 @@ +print [@ +### Generated by scconfig, do not edit ### + +###TODO1### +PCB_SRC=$(PCB_GPMI_ROOT)/../../.. + +PCB_CFLAGS= \ + @/local/global_cflags@ \ + @/target/libs/sul/glib/cflags@ \ + @/target/libs/script/gpmi/cflags@ + + +PCB_LDFLAGS= @/target/libs/script/gpmi/ldflags@ + +@] Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/Makefile =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/Makefile (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/Makefile (revision 1068) @@ -0,0 +1,37 @@ +PCB_GPMI_ROOT=.. +include Makefile.gpmi +include $(PCB_GPMI_ROOT)/Makefile.config + +CFLAGS += -Wall -g -I$(PCB_SRC) $(PCB_CFLAGS) + +COMMON_OBJS = scripts.o manage_scripts.o +BUILDIN_OBJS = gpmi_buildin.o $(COMMON_OBJS) +PLUGIN_OBJS = gpmi_plugin.o $(COMMON_OBJS) + +all: gpmi_plugin.so gpmi_buildin.a + cd gpmi_pkg; make + +all_plugin: gpmi_plugin.so + cd gpmi_pkg; make + +all_buildin: gpmi_buildin.a + cd gpmi_pkg; make + +gpmi_buildin.a: $(BUILDIN_OBJS) + ar rvu gpmi_buildin.a $(BUILDIN_OBJS) + +gpmi_plugin.so: $(PLUGIN_OBJS) + $(CC) $(LDFLAGS) -shared -rdynamic -o gpmi_plugin.so $(PLUGIN_OBJS) $(PCB_LDFLAGS) + +gpmi_plugin.o: gpmi_plugin.c scripts.h + +gpmi_buildin.o: gpmi_plugin.c scripts.h + $(CC) -DPLUGIN_INIT_NAME=hid_gpmi_init $(CFLAGS) -c gpmi_plugin.c -o gpmi_buildin.o + +scripts.o: scripts.c + +manage_scripts.o: manage_scripts.c + +clean: + rm gpmi_plugin.o gpmi_plugin.so gpmi_buildin.a gpmi_buildin.o $(COMMON_OBJS) 2>/dev/null ; true + cd gpmi_pkg; make clean Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.am (revision 1068) @@ -0,0 +1,15 @@ +# This file is package-specific. Do include it in the distribution. +# +# GPMI fingerprint: Makefile.am.ext-pkg + +# End INST_PATH with / +INST_PATH = pcb-gpmi/ +FILE_NAME = actions + +SOURCE = actions.c +HEADER = actions.h + +PKG_LDFLAGS = + +include ../../../Makefile.config +INCLUDES = -I $(PCB_SRC) Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/Makefile.dep (revision 1068) @@ -0,0 +1 @@ +#Please run make depend! Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.c (revision 1068) @@ -0,0 +1,120 @@ +#include +#include +#include +#include +#include "src/global.h" +#include "src/hid.h" +#include "src/error.h" +#include "actions.h" + +typedef struct acontext_s acontext_t; + +struct acontext_s { + HID_Action action; + char *name; + gpmi_module *module; + acontext_t *next; +}; + +static int action_argc = 0; +static char **action_argv = NULL; + +const char *action_arg(int argn) +{ + if ((argn < 0) || (argn >= action_argc)) + return NULL; + return action_argv[argn]; +} + + +static int action_cb(int argc, char **argv, Coord x, Coord y) +{ + acontext_t *ctx = (acontext_t *)current_action; + int action_argc_old; + char **action_argv_old; + + /* save argc/argv for action_arg() */ + action_argc_old = action_argc; + action_argv_old = action_argv; + action_argc = argc; + action_argv = argv; + + /* call event */ + gpmi_event(ctx->module, ACTE_action, ctx->name, argc, x, y); + + /* restore argc/argv of action_arg() */ + action_argc = action_argc_old; + action_argv = action_argv_old; + + return 0; +} + +static void cleanup_action(gpmi_module *mod, gpmi_cleanup *cl) +{ + acontext_t *ctx = cl->argv[0].p; + hid_remove_action(&ctx->action); + free(ctx->action.name); + if (ctx->action.need_coord_msg != NULL) + free((char *)ctx->action.need_coord_msg); + free((char *)ctx->action.description); + free((char *)ctx->action.syntax); + free(ctx); +} + +int action_register(const char *name, const char *need_xy, const char *description, const char *syntax) +{ + acontext_t *ctx; + + + if ((need_xy != NULL) && (*need_xy == '\0')) + need_xy = NULL; + + + ctx = malloc(sizeof(acontext_t)); + ctx->action.name = strdup(name); + ctx->action.need_coord_msg = strdup_null(need_xy); + ctx->action.description = strdup(description); + ctx->action.syntax = strdup(syntax); + ctx->action.trigger_cb = action_cb; + ctx->name = strdup(name); + ctx->module = gpmi_get_current_module(); + ctx->next = NULL; + + hid_register_action(&ctx->action); + + gpmi_mod_cleanup_insert(ctx->module, cleanup_action, "p", ctx); + + printf("registered.\n"); + return 0; +} + +int action(const char *cmdline) +{ + return hid_parse_command(cmdline); +} + +void create_menu(const char *path_, const char *action, const char *mnemonic, const char *hotkey, const char *tooltip) +{ +#define MENU_MAX 32 + const char *menu[MENU_MAX]; + int n; + char *s, *path = strdup(path_); + + menu[0] = path; + for(n = 1, s = path; *s != '\0'; s++) { + if (*s == '/') { + *s = '\0'; + s++; + menu[n] = s; + n++; + if (n == MENU_MAX-1) { + Message("create_menu(): menu path '%s' too long\n", path_); + break; + } + } + } + menu[n] = NULL; + + gui->create_menu(menu, action, mnemonic, hotkey, tooltip); + free(path); +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/actions.h (revision 1068) @@ -0,0 +1,52 @@ +#include + +/* Generated when an action registered by the script is executed. + Arguments: + name: name of the action (as registed using function action_register()) + argc: number of arguments. Arguments can be accessed using function action_arg + x, y: optional coords, if need_xy was not empty at action_register */ +gpmi_define_event(ACTE_action)(const char *name, int argc, int x, int y); + +/* Generated right after gui initialization, before the gui main loop. + Arguments: + argc: number of arguments the gui was initialized with. + argv[]: arguments the gui was initialized with - unaccessible for the scripts. */ +gpmi_define_event(ACTE_gui_init)(int argc, char **argv); + + +/* Generated right before unloading a script to give the script a chance + to clean up. + Arguments: + conffile: the name of the config file that originally triggered laoding the script, or empty if the script was loaded from the gui. */ +gpmi_define_event(ACTE_unload)(const char *conffile); + +/* Register an action in PCB - when the action is executed, event + ACTE_action is generated with the action name. + Multiple actions can be registered. Any action registered by the script + will trigger an ACTE_event sent to the script. + Arguments: + name: name of the action + need_xy: the question the user is asked when he needs to choose a coordinate; if empty, no coordinate is asked + description: description of the action (for the help) + syntax: syntax of the action (for the help) + Returns 0 on success. + */ +int action_register(const char *name, const char *need_xy, const char *description, const char *syntax); + +/* extract the (argn)th event argument for the current action (makes sense only in an ACTE_action event handler */ +const char *action_arg(int argn); + +/* call an existing action using PCB syntax (e.g. foo(1, 2, 3)) + Returns non-zero on error; generally returns value of the action + (which is also non-zero on error). */ +int action(const char *cmdline); + +/* Create a new menu or submenu at path. Missing parents are created + automatically with empty action, mnemonic, hotkey and tooltip. + Arguments: + path: the full path of the new menu + action: this action is executed when the user clicks on the menu + mnemonic: which letter to underline in the menu text (will be the fast-jump-there key once the menu is open) + hotkey: when this key is pressed in the main gui, the action is also triggered; the format is modifiers<Key>letter, where modifiers is Alt, Shift or Ctrl. This is the same syntax that is used in the .res files. + tooltip: short help text */ +void create_menu(const char *path, const char *action, const char *mnemonic, const char *hotkey, const char *tooltip); Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi/package.c (revision 1068) @@ -0,0 +1,19 @@ +#include + +int PKG_FUNC(init)() +{ + return 0; +} + +void PKG_FUNC(uninit)() { +} + +void PKG_FUNC(register)() { +} + +int PKG_FUNC(checkver)(int requested) { + if (requested <= 1) + return 0; + + return -1; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/actions/gpmi.conf (revision 1068) @@ -0,0 +1,18 @@ +@/local/headers + actions.h + +@/local/srcs + actions.c + +@/local/file_name + actions + +@/local/inst_path + actions + +@/local/CFLAGS + -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### + +@@/local/hook/postall + PCB_GPMI_ROOT=../../.. + include $(PCB_GPMI_ROOT)/Makefile.config Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.am (revision 1068) @@ -0,0 +1,17 @@ +# This file is package-specific. Do include it in the distribution. +# +# GPMI fingerprint: Makefile.am.ext-pkg + +# End INST_PATH with / +INST_PATH = pcb-gpmi/ +FILE_NAME = coordgeo + +SOURCE = coordgeo.c +HEADER = coordgeo.h + +PKG_LDFLAGS = -lm + +include ../../../Makefile.config +INCLUDES = -I $(PCB_SRC) + +test: test.o coordgeo.o Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/Makefile.dep (revision 1068) @@ -0,0 +1 @@ +#Please run make depend! Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.c (revision 1068) @@ -0,0 +1,578 @@ +#include +#include +#include "coordgeo.h" +cg_obj_t *cg_objs = NULL; +int cg_objs_used = 0, cg_objs_alloced = 0; + +#define DEGMPY 10000.0 +#define PI 3.141592654 + +#define OBJ(i) cg_objs[i] +#define OBJ_VALID(i) ((i >= 0) && (i < cg_objs_used)) + +/* todo */ +#define invalid -0xFFFF + +static int oalloc() +{ + int id; + if (cg_objs_used >= cg_objs_alloced) { + cg_objs_alloced = cg_objs_used + 128; + cg_objs = realloc(cg_objs, sizeof(cg_obj_t) * cg_objs_alloced); + } + id = cg_objs_used; + cg_objs_used++; + return id; +} + +static void ofree(int id) +{ + /* todo */ +} + +int cg_new_object(cg_obj_type_t type, int x1, int y1, int x2, int y2, int r) +{ + int id; + + id = oalloc(); + OBJ(id).type = type; + OBJ(id).x1 = x1; + OBJ(id).y1 = y1; + OBJ(id).x2 = x2; + OBJ(id).y2 = y2; + OBJ(id).r = r; + return id; +} + +static inline int cg_clone_object_(cg_obj_t *o) +{ + int id; + + id = oalloc(); + OBJ(id) = *o; + return id; +} + +int cg_clone_object(int objID) +{ + return cg_clone_object_(&OBJ(objID)); +} + +/* destroys an object by ID */ +void cg_destroy_object(int ID) +{ + ofree(ID); +} + +/* -- field accessors -- */ +cg_obj_type_t cg_get_type(int objID) +{ + return OBJ(objID).type; +} + +int cg_get_coord(int objID, cg_coord_t coordname) +{ + switch(coordname) { + case CG_X1: return OBJ(objID).x1; + case CG_Y1: return OBJ(objID).y1; + case CG_X2: return OBJ(objID).x2; + case CG_Y2: return OBJ(objID).y2; + case CG_R: return OBJ(objID).r; + } + return invalid; +} + +void cg_set_coord(int objID, cg_coord_t coordname, int newvalue) +{ + switch(coordname) { + case CG_X1: OBJ(objID).x1 = newvalue; + case CG_Y1: OBJ(objID).y1 = newvalue; + case CG_X2: OBJ(objID).x2 = newvalue; + case CG_Y2: OBJ(objID).y2 = newvalue; + case CG_R: OBJ(objID).r = newvalue; + } +} + + +/* -- object operations -- */ +double cg_dist_(int x1, int y1, int x2, int y2) +{ + int dx, dy; + + dx = x2 - x1; + dy = y2 - y1; + return sqrt(dx * dx + dy * dy); +} + +int cg_solve_quad(double a, double b, double c, double *x1, double *x2) +{ + double d; + + d = b * b - 4 * a * c; + if (d < 0) + return 0; + if (d != 0) + d = sqrt(d); + + if (x1 != NULL) + *x1 = (-b + d) / (2 * a); + + if (x2 != NULL) + *x2 = (-b - d) / (2 * a); + + if (d == 0) + return 1; + return 2; +} + + +/* return ID to a new object which is parallel obj in distance dist + - for a line dist > 0 means a new line right to the original + (looking from x1;y1 towards x2;y2) + - for arc the same rule applies, looking from angle x2 towards y2 + - for circle dist > 0 means smaller concentric circle + - for point and vector always returns invalid +*/ +int cg_para_obj(int objID, int dist) +{ + cg_obj_t v1, v2; + int rid; + + switch(OBJ(objID).type) { + case CG_POINT: + case CG_VECTOR: + return -1; + case CG_ARC: + /* TODO */ + abort(); + break; + case CG_CIRCLE: + rid = cg_clone_object(objID); + OBJ(rid).r -= dist; + return rid; + case CG_LINE: + cg_perp_line_(&OBJ(objID), &v1, OBJ(objID).x1, OBJ(objID).y1, dist); + cg_perp_line_(&OBJ(objID), &v2, OBJ(objID).x2, OBJ(objID).y2, dist); + rid = oalloc(); + OBJ(rid).type = CG_LINE; + OBJ(rid).x1 = v1.x2; + OBJ(rid).y1 = v1.y2; + OBJ(rid).x2 = v2.x2; + OBJ(rid).y2 = v2.y2; + OBJ(rid).r = 0; + return rid; + } + return -1; +} + +void cg_perp_line_(const cg_obj_t *i, cg_obj_t *o, int xp, int yp, int len) +{ + double dx, dy, dl; + + dx = -(i->y2 - i->y1); + dy = +(i->x2 - i->x1); + dl = sqrt(dx * dx + dy * dy); + dx = dx / dl; + dy = dy / dl; + + o->type = CG_LINE; + o->x1 = xp; + o->y1 = yp; + o->x2 = round((double)xp + dx * (double)len); + o->y2 = round((double)yp + dy * (double)len); + o->r = 0; +} + + +/* return ID to a new line which is perpendicular to line1 and starts at + point xp;yp and is len long */ +int cg_perp_line(int line1ID, int xp, int yp, int len) +{ + int id; + + id = oalloc(); + cg_perp_line_(&OBJ(line1ID), &OBJ(id), xp, yp, len); + + return id; +} + +int cg_ison_line_(cg_obj_t *l, int x, int y, int extend) +{ + int vx, vy; + + vx = l->x2 - l->x1; + vy = l->y2 - l->y1; + + /* is the point on the extended line? */ + if ((vy * x - vx * y) != (vy * l->x1 - vy * l->y1)) + return 0; + + if ((!extend) && ((x < l->x1) || (x > l->x2))) + return 0; + return 1; +} + +int cg_ison_arc_(cg_obj_t *a, int x, int y, int extend) +{ + double deg; + + /* is the point on the circle? */ + if (cg_dist_(a->x1, a->y1, x, y) != a->r) + return 0; + + /* for circles (or an extended arc, which is just a circle) this means the point must be on */ + if (extend || (a->type == CG_CIRCLE)) + return 1; + + /* check if the point is between start and end angles */ + deg = atan2(y - a->y1, x - a->x1) * DEGMPY; + if ((deg >= a->x2) && (deg >= a->y2)) + return 1; + + return 0; +} + +int cg_ison_point_(cg_obj_t *p, int x, int y) +{ + return (p->x1 == x) && (p->y1 == y); +} + +int cg_ison_(cg_obj_t *o, int x, int y, int extend) +{ + switch(o->type) { + case CG_POINT: return cg_ison_point_(o, x, y); + case CG_VECTOR: return 1; + case CG_LINE: return cg_ison_line_(o, x, y, extend); + case CG_ARC: return cg_ison_arc_(o, x, y, extend); + case CG_CIRCLE: return cg_ison_circle_(o, x, y); + } + + /* can't get here */ + abort(); + return 0; +} + +/* intersection of 2 lines (always returns 1) */ +int cg_intersect_ll(cg_obj_t *l1, cg_obj_t *l2, cg_obj_t *o) +{ + double ua, ub, xi, yi, X1, Y1, X2, Y2, X3, Y3, X4, Y4, tmp; + + /* maths from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/ */ + + X1 = l1->x1; + X2 = l1->x2; + X3 = l2->x1; + X4 = l2->x2; + Y1 = l1->y1; + Y2 = l1->y2; + Y3 = l2->y1; + Y4 = l2->y2; + + tmp = ((Y4-Y3)*(X2-X1) - (X4-X3)*(Y2-Y1)); + ua=((X4-X3)*(Y1-Y3) - (Y4-Y3)*(X1-X3)) / tmp; + ub=((X2-X1)*(Y1-Y3) - (Y2-Y1)*(X1-X3)) / tmp; + xi = X1 + ua * (X2 - X1); + yi = Y1 + ua * (Y2 - Y1); + + o->type = CG_LINE; + o->x1 = o->x2 = round(xi); + o->y1 = o->y2 = round(yi); + o->r = 0; + return 1; +} + +/* intersections of a line and a circle (returns number of possible intersections) */ +int cg_intersect_lc(cg_obj_t *l, cg_obj_t *c, cg_obj_t *o) +{ + int x1, y1, vx, vy, a, vx2, ints; + double A, B, C, X1, X2, Y1, Y2; + + /* first we transform the line to the coordinate system with origo in the + center of the circle - this will simplify the equations */ + x1 = l->x1 - c->x1; + y1 = l->y1 - c->y1; + vx = l->x2 - l->x1; + vy = l->y2 - l->y1; + + /* some cache */ + a = vy * x1 - vx * y1; + vx2 = vx * vx; + + /* this quadratic equation results in the two intersections, X1 and X2 */ + A = 1+vy*vy/vx2; + B = - 2*a*vy / (vx2); + C = a*a / vx2 - c->r * c->r; + + ints = cg_solve_quad(A, B, C, &X1, &X2); + if (ints == 0) + return 0; + + /* knowing X1 and X2 we can easily get Y1 and Y2 */ + Y1 = (a - vy * X1) / (-vx); + Y2 = (a - vy * X2) / (-vx); + + /* transoform back to the original coordinate system */ + X1 += c->x1; + X2 += c->x1; + Y1 += c->y1; + Y2 += c->y1; + + /* set up return line and return number of intersections */ + o->type = CG_LINE; + o->x1 = X1; + o->y1 = Y1; + o->x2 = X2; + o->y2 = Y2; + o->r = 0; + return ints; +} + +/* intersections of 2 circles (returns number of possible intersections) */ +int cg_intersect_cc(cg_obj_t *c1, cg_obj_t *c2, cg_obj_t *o) +{ + double d, a, h; + int P2x, P2y; + + d = cg_dist_(c1->x1, c1->y1, c2->x1, c2->y1); + + if (d > c1->r + c2->r) + return 0; /* separate */ + if (d < abs(c1->r - c2->r)) + return 0; /* contained */ + if ((d == 0) && (c1->r == c2->r)) + return -1; /* they are the same circle */ + + /* some temps */ + a = (double)(c1->r * c1->r - c2->r * c2->r + d * d) / (2.0 * d); + h = sqrt(c1->r * c1->r - a * a); + P2x = c1->x1 + a * (c2->x1 - c1->x1) / d; + P2y = c1->y1 + a * (c2->y1 - c1->y1) / d; + + /* final coordinates */ + o->type = CG_LINE; + o->x1 = P2x + h * (c2->y1 - c1->y1) / d; + o->y1 = P2y - h * (c2->x1 - c1->x1) / d; + o->x2 = P2x - h * (c2->y1 - c1->y1) / d; + o->y2 = P2y + h * (c2->x1 - c1->x1) / d; + + if (d == c1->r + c2->r) + return 1; + return 2; +} + + +int cg_intersect_(cg_obj_t *i1, cg_obj_t *i2, cg_obj_t *o) +{ + switch(i1->type) { + case CG_VECTOR: + /* invalid */ + return -1; + case CG_POINT: + /* TODO: ison */ + break; + case CG_LINE: + switch(i2->type) { + case CG_VECTOR: + /* invalid */ + return -1; + case CG_POINT: + /* TODO: ison */ + break; + case CG_LINE: + return cg_intersect_ll(i1, i2, o); + case CG_CIRCLE: + case CG_ARC: + return cg_intersect_lc(i1, i2, o); + } + return -1; + case CG_CIRCLE: + case CG_ARC: + switch(i2->type) { + case CG_VECTOR: + /* invalid */ + return -1; + case CG_POINT: + /* TODO: ison */ + break; + case CG_LINE: + return cg_intersect_lc(i2, i1, o); + case CG_CIRCLE: + case CG_ARC: + return cg_intersect_cc(i1, i2, o); + } + return -1; + } + return -1; +} + +int cg_intersect(int obj1ID, int obj2ID, int extend) +{ + cg_obj_t res; + int ints; + + ints = cg_intersect_(&OBJ(obj1ID), &OBJ(obj2ID), &res); + + /* if we needed to extend, we shouldn't care if the intersections + are on the objects. */ + if (extend) + return cg_clone_object_(&res); + + + while(1) { + if (ints == 0) + return -1; + + if ((!cg_ison_(&OBJ(obj1ID), res.x1, res.y1, 0)) || (!cg_ison_(&OBJ(obj2ID), res.x1, res.y1, 0))) { + /* x1;y1 is not on the objects. make x2;y2 the new x1;y1 and test again */ + res.x1 = res.x2; + res.y1 = res.y2; + ints--; + } + else + break; + } + + /* x1;y1 is on the objects; check x2;y2 if we still have 2 intersections */ + if ((ints == 2) && ((!cg_ison_(&OBJ(obj1ID), res.x2, res.y2, 0)) || (!cg_ison_(&OBJ(obj2ID), res.x2, res.y2, 0)))) { + /* x2;y2 not on the objects, kill it */ + res.x2 = res.x1; + res.y2 = res.y1; + ints = 1; + } + + return cg_clone_object_(&res); +} + +/* Truncate an object at x;y. Point x;y must be on the object. Optionally + invert which part is kept. Default: + - line: keep the part that originates from x1;y1 + - arc: keep the segment that is closer to the starting angle (x2) + - circle: always fails + - point: always fails + - vector: always fails + Returns 0 on success. +*/ +int cg_truncate_(cg_obj_t *o, int x, int y, int invert_kept) +{ + double a; + + /* point is not on the object */ + if (!cg_ison_(o, x, y, 0)) + return 1; + + switch(o->type) { + case CG_VECTOR: + case CG_POINT: + case CG_CIRCLE: + return 2; + case CG_LINE: + if (!invert_kept) { + o->x2 = x; + o->y2 = y; + } + else { + o->x1 = x; + o->y1 = y; + } + break; + case CG_ARC: + a = atan2(y - o->y1, x - o->x1) * DEGMPY; + if (!invert_kept) + o->y2 = a; + else + o->x2 = a; + break; + } + return 0; +} + +int cg_truncate(int objID, int x, int y, int invert_kept) +{ + return cg_truncate_(&OBJ(objID), x, y, invert_kept); +} + +/* cut target object with cutting edge object; optionally invert which + part is kept of target. Default: + - when line cuts, looking from x1;y1 towards x2;y2, right is kept + - when circle or arc cuts, we are "walking" clock-wise, right is kept + (in short, inner part is kept) + Returns 0 on success. +*/ +int cg_cut_(cg_obj_t *t, cg_obj_t *c, int invert_kept) +{ + cg_obj_t intersects; + int num_intersects, ni; + + num_intersects = cg_intersect_(t, c, &intersects); + if (num_intersects < 1) + return 1; + + for(; num_intersects > 0; num_intersects--) + { + switch(c->type) { + case CG_POINT: + case CG_VECTOR: + return 1; + case CG_LINE: + /* TODO: leftof */ + return 1; + case CG_CIRCLE: + case CG_ARC: + /* TODO: leftof */ + break; + } + /* shift intersection */ + intersects.x1 = intersects.x2; + intersects.y1 = intersects.y2; + } + return 0; +} + +int cg_cut(int targetID, int cutting_edgeID, int invert_kept); + +cg_obj_t *cg_get_object(int ID) +{ + if (OBJ_VALID(ID)) + return &OBJ(ID); + else + return NULL; +} + +int cg_simplify_object_(cg_obj_t *o) +{ + int ret = 0; /* no direct returns because CG_ARC can have more than one optimization */ + switch(o->type) { + case CG_LINE: + if ((o->x1 == o->x2) && (o->y1 == o->y2)) { + o->type = CG_POINT; + ret++; + break; + } + break; + case CG_ARC: + if ((fabs(o->x2 - o->y2) * DEGMPY) >= 2*PI) { + o->type = CG_CIRCLE; + ret++; + } + /* intended fall trough for r==0 check */ + case CG_CIRCLE: + if (o->r == 0) { + o->type = CG_POINT; + ret++; + break; + } + break; + default: + /* no simplification possible */ + ; + } + return ret; +} + + +int cg_simplify_object(int ID) +{ + if (OBJ_VALID(ID)) + return cg_simplify_object_(&OBJ(ID)); + return -1; +} \ No newline at end of file Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/coordgeo.h (revision 1068) @@ -0,0 +1,123 @@ +#include + +typedef enum cg_obj_type_e { + CG_POINT, /* x1;y1 */ + CG_LINE, /* from x1;y1 to x2;y2 */ + CG_VECTOR, /* x1;y1 (not associated with a point) */ + CG_CIRCLE, /* center x1;y1, radius r */ + CG_ARC /* center x1;y1, radius r, from x2 rad to y2 rad */ +} cg_obj_type_t; + +typedef enum cg_coord_e { + CG_X1, + CG_Y1, + CG_X2, + CG_Y2, + CG_R +} cg_coord_t; + + +/* -- object administration -- */ +/* returns ID to the new object */ +int cg_new_object(cg_obj_type_t type, int x1, int y1, int x2, int y2, int r); + +/* cloned an existing object and returns ID to the new object */ +int cg_clone_object(int objID); + +/* destroys an object by ID */ +void cg_destroy_object(int ID); + +/* -- field accessors -- */ +cg_obj_type_t cg_get_type(int objID); +int cg_get_coord(int objID, cg_coord_t coordname); +void cg_set_coord(int objID, cg_coord_t coordname, int newvalue); + + +/* -- object operations -- */ +/* return ID to a new object which is parallel obj in distance dist + - for a line dist > 0 means a new line right to the original + (looking from x1;y1 towards x2;y2) + - for arc the same rule applies, looking from angle x2 towards y2 + - for circle dist > 0 means smaller concentric circle + - for point and vector always returns invalid +*/ +int cg_para_obj(int objID, int dist); + +/* return ID to a new line which is perpendicular to line1 and starts at + point xp;yp and is len long */ +int cg_perp_line(int line1ID, int xp, int yp, int len); + +/* returns ID to a line which marks the intersection(s) of two objects or + returns -1 if there's no intersection. If there's only one intersection, + the start and end point of the line is the same point. With the current + primitives, there can not be more than 2 intersections between 2 objects, + except when they have infinite amount of intersections: + - overlapping lines + - overlapping arcs + - two circles with the same radius and center + If extend is non-zero, the objects are extended during the calculation. + For lines this means infinite length, for arcs this means handling them as + circles. +*/ +int cg_intersect(int obj1ID, int obj2ID, int extend); + +/* Truncate an object at x;y. Point x;y must be on the object. Optionally + invert which part is kept. Default: + - line: keep the part that originates from x1;y1 + - arc: keep the segment that is closer to the starting angle (x2) + - circle: always fails + - point: always fails + - vector: always fails + Returns 0 on success. +*/ +int cg_truncate(int objID, int x, int y, int invert_kept); + +/* cut target object with cutting edge object; optionally invert which + part is kept of target. Defaults: + - when line cuts, looking from x1;y1 towards x2;y2, right is kept + - when circle or arc cuts, we are "walking" clock-wise, right is kept + (in short, inner part is kept) + - vector and point fails + Returns 0 on success. +*/ +int cg_cut(int targetID, int cutting_edgeID, int invert_kept); + +/* Convert object to simpler form, if possible: + - if x1;y1 and x2;y2 are equal in a line, it is converted to a point + - if radius of a circle or arc is zero, it is converted to a point + - if an arc is a full circle, convert it to a circle + Returns number of simplifications (0, 1 or 2) issued or -1 for + invalid object ID. +*/ +int cg_simplify_object(int ID); + + +/* these are for C API, scripts have no direct access */ +typedef struct cg_obj_s { + cg_obj_type_t type; + int x1, y1, x2, y2; + int r; +} cg_obj_t; + +extern cg_obj_t *cg_objs; +extern int cg_objs_used, cg_objs_alloced; + +nowrap cg_obj_t *cg_get_object(int ID); + +/* create a line in o that is perpendicular to i and starts at point xp and yp */ +nowrap void cg_perp_line_(const cg_obj_t *i, cg_obj_t *o, int xp, int yp, int len); + +/* distance */ +nowrap double cg_dist_(int x1, int y1, int x2, int y2); + +/* is point on the object? Extend means the object is extended (lines become + infinite long, arcs become circles). Vector always returns 1. */ +nowrap int cg_ison_(cg_obj_t *o, int x, int y, int extend); +nowrap int cg_ison_line_(cg_obj_t *l, int x, int y, int extend); +nowrap int cg_ison_arc_(cg_obj_t *a, int x, int y, int extend); +nowrap int cg_ison_point_(cg_obj_t *p, int x, int y); +#define cg_ison_circle_(c, x, y) cg_ison_arc_(c, x, y, 1) + +/* these calls are the low level versions of the ones defined for scripts above */ +nowrap int cg_simplify_object_(cg_obj_t *o); + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi/package.c (revision 1068) @@ -0,0 +1,19 @@ +#include + +int PKG_FUNC(init)() +{ + return 0; +} + +void PKG_FUNC(uninit)() { +} + +void PKG_FUNC(register)() { +} + +int PKG_FUNC(checkver)(int requested) { + if (requested <= 1) + return 0; + + return -1; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/gpmi.conf (revision 1068) @@ -0,0 +1,18 @@ +@/local/headers + coordgeo.h + +@/local/srcs + coordgeo.c + +@/local/file_name + coordgeo + +@/local/inst_path + coordgeo + +@/local/CFLAGS + -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### + +@@/local/hook/postall + PCB_GPMI_ROOT=../../.. + include $(PCB_GPMI_ROOT)/Makefile.config Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/coordgeo/test.c (revision 1068) @@ -0,0 +1,199 @@ +#include +#include +#include +#include "coordgeo.h" + +#define POINT_MARK_SIZE 2 +#define PS_SCALE 3 +#define PS_MARGIN 8 + +#define SCALE(v) ((v+PS_MARGIN) * PS_SCALE) + +void line(FILE *ps, int x1, int y1, int x2, int y2) +{ + fprintf(ps, "%d %d moveto\n", SCALE(x1), SCALE(y1)); + fprintf(ps, "%d %d lineto\n", SCALE(x2), SCALE(y2)); +} + +void color(FILE *ps, float r, float g, float b) +{ + static int colorspace=0; + + if (colorspace == 0) { + fprintf(ps, "/DeviceRGB setcolorspace\n"); + colorspace = 1; + } + fprintf(ps, "%f %f %f setcolor\n", r, g, b); +} + + +FILE *ps_start(const char *fn) +{ + FILE *f; + + f = fopen(fn, "w"); + if (f == NULL) + return NULL; + + fprintf(f, "%%!\n"); + + return f; +} + +int ps_draw(FILE *ps, int ID) +{ + cg_obj_t *o; + o = cg_get_object(ID); + assert(o != NULL); + fprintf(ps, "newpath\n"); + + switch(o->type) { + case CG_POINT: + fprintf(ps, "0.1 setlinewidth\n"); + line(ps, o->x1-POINT_MARK_SIZE, o->y1, o->x1+POINT_MARK_SIZE, o->y1); + line(ps, o->x1, o->y1-POINT_MARK_SIZE, o->x1, o->y1+POINT_MARK_SIZE); + break; + case CG_LINE: + fprintf(ps, "0.1 setlinewidth\n"); + line(ps, o->x1, o->y1, o->x2, o->y2); + break; + case CG_VECTOR: + fprintf(ps, "0.1 setlinewidth\n"); + line(ps, o->x1, o->y1, o->x2, o->y2); + break; + case CG_CIRCLE: + fprintf(ps, "0.1 setlinewidth\n"); + fprintf(ps, "%d %d %d %d %d arc\n", SCALE(o->x1), SCALE(o->y1), o->r*PS_SCALE, 0, 360); + break; + case CG_ARC: + fprintf(ps, "0.1 setlinewidth\n"); + fprintf(ps, "%d %d %d %d %d arc\n", SCALE(o->x1), SCALE(o->y1), o->r*PS_SCALE, o->x2, o->y2); + break; + } + + fprintf(ps, "stroke\n"); + return ID; +} + +void ps_end(FILE *ps) +{ + fprintf(ps, "showpage\n"); + fclose(ps); +} + +void test_primitives() +{ + FILE *ps; + + ps = ps_start("primitives.ps"); + cg_destroy_object(ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0))); + cg_destroy_object(ps_draw(ps, cg_new_object(CG_VECTOR, 20, 0, 30, 10, 0))); + cg_destroy_object(ps_draw(ps, cg_new_object(CG_POINT, 40, 5, 0, 0, 0))); + cg_destroy_object(ps_draw(ps, cg_new_object(CG_CIRCLE, 70, 10, 0, 0, 5))); + cg_destroy_object(ps_draw(ps, cg_new_object(CG_ARC, 90, 10, 0, 45, 5))); + ps_end(ps); +} + +void test_parallels() +{ + FILE *ps; + int obj; + + ps = ps_start("parallels.ps"); + + obj = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); + cg_destroy_object(obj); + + obj = ps_draw(ps, cg_new_object(CG_CIRCLE, 70, 10, 0, 0, 5)); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); + cg_destroy_object(obj); + +/* obj = ps_draw(ps, cg_new_object(CG_ARC, 90, 10, 0, 45, 5)); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, 4))); + cg_destroy_object(ps_draw(ps, cg_para_obj(obj, -4))); + cg_destroy_object(obj);*/ + + + ps_end(ps); + +} + +void test_perps() +{ + FILE *ps; + int obj; + + ps = ps_start("perpendicular.ps"); + + obj = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); + cg_destroy_object(ps_draw(ps, cg_perp_line(obj, 0,0,4))); + cg_destroy_object(ps_draw(ps, cg_perp_line(obj, 10,10,-4))); + cg_destroy_object(obj); + + ps_end(ps); + +} + +void test_intersect() +{ + FILE *ps; + int o1, o2, i; + cg_obj_t *oi; + + ps = ps_start("intersect.ps"); + + /* two lines, intersecting */ + color(ps, 0, 0, 0); + o1 = ps_draw(ps, cg_new_object(CG_LINE, 0, 0, 10, 10, 0)); + o2 = ps_draw(ps, cg_new_object(CG_LINE, 5, 0, 6, 13, 0)); + color(ps, 1, 0, 0); + cg_simplify_object(i = cg_intersect(o1, o2, 1)); + cg_destroy_object(ps_draw(ps, i)); + cg_destroy_object(o1); + cg_destroy_object(o2); + + /* two lines, no visible intersection */ + color(ps, 0, 0, 0); + o1 = ps_draw(ps, cg_new_object(CG_LINE, 20, 0, 30, 10, 0)); + o2 = ps_draw(ps, cg_new_object(CG_LINE, 25, 0, 32, 13, 0)); + color(ps, 1, 0, 0); + cg_simplify_object(i = cg_intersect(o1, o2, 1)); + cg_destroy_object(ps_draw(ps, i)); + cg_destroy_object(o1); + cg_destroy_object(o2); + + /* circle vs. line */ + color(ps, 0, 0, 0); + o1 = ps_draw(ps, cg_new_object(CG_LINE, 40, 0, 55, 15, 0)); + o2 = ps_draw(ps, cg_new_object(CG_CIRCLE, 45, 8, 0, 0, 6)); + color(ps, 1, 0, 0); + cg_simplify_object(i = cg_intersect(o1, o2, 1)); + cg_destroy_object(ps_draw(ps, i)); + cg_destroy_object(o1); + cg_destroy_object(o2); + + /* circle vs. circle */ + color(ps, 0, 0, 0); + o1 = ps_draw(ps, cg_new_object(CG_CIRCLE, 69, 6, 0, 0, 4)); + o2 = ps_draw(ps, cg_new_object(CG_CIRCLE, 65, 8, 0, 0, 6)); + color(ps, 1, 0, 0); + cg_simplify_object(i = cg_intersect(o1, o2, 1)); + cg_destroy_object(ps_draw(ps, i)); + cg_destroy_object(o1); + cg_destroy_object(o2); + + + ps_end(ps); +} + + +int main() +{ + test_primitives(); + test_parallels(); + test_perps(); + test_intersect(); +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.am (revision 1068) @@ -0,0 +1,16 @@ +# This file is package-specific. Do include it in the distribution. +# +# GPMI fingerprint: Makefile.am.ext-pkg + +# End INST_PATH with / +INST_PATH = pcb-gpmi/ +FILE_NAME = dialogs + +SOURCE = dialogs.c +HEADER = dialogs.h + +PKG_LDFLAGS = + +PCB_GPMI_ROOT=../../.. +include $(PCB_GPMI_ROOT)/Makefile.config +INCLUDES = -I.. -I../.. -I $(PCB_SRC) Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/Makefile.dep (revision 1068) @@ -0,0 +1 @@ +#Please run make depend! Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.c (revision 1068) @@ -0,0 +1,90 @@ +#include "dialogs.h" +#include "src/error.h" + +extern HID *gui; + +void dialog_log(const char *msg) +{ + if (gui == NULL) + fprintf(stderr, "couldn't find gui for log: \"%s\"\n", msg); + else + Message("%s", msg); +} + +#define empty(s) (((s) == NULL) || ((*s) == '\0')) +int dialog_confirm(const char *msg, const char *ok, const char *cancel) +{ + if (gui == NULL) { + fprintf(stderr, "couldn't find gui for dialog_confirm: \"%s\"\n", msg); + return -1; + } + + if (empty(ok)) + ok = NULL; + if (empty(cancel)) + cancel = NULL; + + return gui->confirm_dialog(msg, cancel, ok, NULL); +} +#undef empty + +void dialog_report(const char *title, const char *msg) +{ + if (gui == NULL) + fprintf(stderr, "couldn't find gui for dialog_report: \"%s\" \"%s\"\n", title, msg); + else + gui->report_dialog(title, msg); +} + +dynamic char *dialog_prompt(const char *msg, const char *default_) +{ + if (gui == NULL) { + fprintf(stderr, "couldn't find gui for dialog_prompt: \"%s\" \"%s\"\n", msg, default_); + return NULL; + } + else + return gui->prompt_for(msg, default_); +} + +dynamic char *dialog_fileselect(const char *title, const char *descr, char *default_file, char *default_ext, const char *history_tag, multiple dialog_fileselect_t flags) +{ + if (gui == NULL) { + fprintf(stderr, "couldn't find gui for dialog_fileselect\n"); + return NULL; + } + else + return gui->fileselect(title, descr, default_file, default_ext, history_tag, flags); +} + +void dialog_beep(void) +{ + if (gui == NULL) + fprintf(stderr, "couldn't find gui for dialog_beep\n"); + else + gui->beep(); +} + +int dialog_progress(int so_far, int total, const char *message) +{ + if (gui == NULL) { + fprintf(stderr, "couldn't find gui for dialog_process: %d/%d \"%s\"\n", so_far, total, message); + return -1; + } + return gui->progress(so_far, total, message); +} + +int dialog_attribute(hid_t *hid, const char *title, const char *descr) +{ + if (gui == NULL) { + fprintf(stderr, "couldn't find gui for dialog_attribute: \"%s\" \"%s\"\n", title, descr); + return -1; + } + + if (hid->result != NULL) { + /* TODO: free string fields to avoid memleaks */ + } + else + hid->result = calloc(sizeof(HID_Attribute), hid->attr_num); + + return gui->attribute_dialog(hid->attr, hid->attr_num, hid->result, title, descr); +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/dialogs.h (revision 1068) @@ -0,0 +1,74 @@ +#include +#include "src/global.h" +#define FROM_PKG +#include "hid/hid.h" + +/* Filter on what files a file select dialog should list */ +typedef enum dialog_fileselect_e { + FS_NONE = 0, /* none of the below */ + FS_READ = 1, /* when the selected file will be read, not written (HID_FILESELECT_READ) */ + FS_NOT_EXIST = 2, /* the function calling hid->fileselect will deal with the case when the selected file already exists. If not given, then the gui will prompt with an "overwrite?" prompt. Only used when writing. (HID_FILESELECT_MAY_NOT_EXIST) */ + FS_TEMPLATE = 4 /* the call is supposed to return a file template (for gerber output for example) instead of an actual file. Only used when writing. (HID_FILESELECT_IS_TEMPLATE) */ +} dialog_fileselect_t; +gpmi_keyword *kw_dialog_fileselect_e; /* of dialog_fileselect_t */ + +/* Append a msg to the log (log window and/or stderr). */ +void dialog_log(const char *msg); + +/* Ask the user for confirmation (usually using a popup). Returns 0 for + cancel and 1 for ok. + Arguments: + msg: message to the user + ok: label of the OK button + cancel: label of the cancel button + Arguments "ok" and "cancel" may be empty (or NULL) in which + case the GUI will use the default (perhaps localized) labels for + those buttons. */ +int dialog_confirm(const char *msg, const char *ok, const char *cancel); + + +/* Pop up a report dialog. + Arguments: + title: title of the window + msg: message */ +void dialog_report(const char *title, const char *msg); + +/* Ask the user to input a string (usually in a popup). + Arguments: + msg: message or question text + default_: default answer (this may be filled in on start) + Returns the answer. */ +dynamic char *dialog_prompt(const char *msg, const char *default_); + +/* Pops up a file selection dialog. + Arguments: + title: window title + descr: description + default_file_ + default_ext: default file name extension + history_tag + flags: one or more flags (see below) + Returns the selected file or NULL (empty). */ +dynamic char *dialog_fileselect(const char *title, const char *descr, char *default_file_, char *default_ext, const char *history_tag, multiple dialog_fileselect_t flags); + +/* Audible beep */ +void dialog_beep(void); + +/* Request the GUI hid to draw a progress bar. + Arguments: + int so_far: achieved state + int total: maximum state + const char *message: informs the users what they are waiting for + If so_far is bigger than total, the progress bar is closed. + Returns nonzero if the user wishes to cancel the operation. +*/ +int dialog_progress(int so_far, int total, const char *message); + + +/* Pop up an attribute dialog; content (widgets) of the dialog box are coming + from hid (see the hid package). + Arguments: + hid: widgets + title: title of the window + descr: descripting printed in the dialog */ +int dialog_attribute(hid_t *hid, const char *title, const char *descr); Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/dialogs/gpmi.conf (revision 1068) @@ -0,0 +1,18 @@ +@/local/headers + dialogs.h + +@/local/srcs + dialogs.c + +@/local/file_name + dialogs + +@/local/inst_path + dialogs + +@/local/CFLAGS + -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### + +@@/local/hook/postall + PCB_GPMI_ROOT=../../.. + include $(PCB_GPMI_ROOT)/Makefile.config Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.am (revision 1068) @@ -0,0 +1,13 @@ +# GPMI fingerprint: Makefile.am.ext-pkg + +# End INST_PATH with / +INST_PATH = pcb-gpmi/ +FILE_NAME = hid + +SOURCE = hid.c +SOURCE += hid_callbacks.c + +HEADER = hid.h +HEADER += hid_events.h +include ../../../Makefile.config +INCLUDES = -I $(PCB_SRC) Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/Makefile.dep (revision 1068) @@ -0,0 +1 @@ +#Please run make depend! Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi/package.c (revision 1068) @@ -0,0 +1,19 @@ +#include + +int PKG_FUNC(init)() +{ + return 0; +} + +void PKG_FUNC(uninit)() { +} + +void PKG_FUNC(register)() { +} + +int PKG_FUNC(checkver)(int requested) { + if (requested <= 1) + return 0; + + return -1; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/gpmi.conf (revision 1068) @@ -0,0 +1,20 @@ +@/local/headers + hid.h + hid_events.h + +@/local/srcs + hid.c + hid_callbacks.c + +@/local/file_name + hid + +@/local/inst_path + hid + +@/local/CFLAGS + -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### + +@@/local/hook/postall + PCB_GPMI_ROOT=../../.. + include $(PCB_GPMI_ROOT)/Makefile.config Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.c (revision 1068) @@ -0,0 +1,304 @@ +#include +#include +#include +#include +#include "src/global.h" +#include "src/error.h" +#include "src/hid.h" +#include "src/hid/common/hidnogui.h" +#include "src/hid/hidint.h" +#include "src/pcb-printf.h" +#define FROM_PKG +#include "hid.h" +#include "hid_callbacks.h" + + +void hid_gpmi_data_set(hid_t *h, void *data) +{ + h->hid->user_context = data; +} + +hid_t *hid_gpmi_data_get(HID *h) +{ + if (h == NULL) + return NULL; + return (hid_t *)h->user_context; +} + +hid_t *hid_create(char *hid_name, char *description) +{ + hid_t *h; + + h = calloc(sizeof(hid_t), 1); + h->hid = calloc(sizeof(HID), 1); + + common_nogui_init (h->hid); + + h->module = gpmi_get_current_module(); + + h->hid->name = strdup(hid_name); + h->hid->description = strdup(description); + h->hid->exporter = 1; + h->hid->gui = 0; + h->hid->struct_size = sizeof(HID); + + h->hid->get_export_options = gpmi_hid_get_export_options; + h->hid->make_gc = gpmi_hid_make_gc; + h->hid->destroy_gc = gpmi_hid_destroy_gc; + h->hid->do_export = gpmi_hid_do_export; + h->hid->parse_arguments = gpmi_hid_parse_arguments; + h->hid->set_crosshair = gpmi_hid_set_crosshair; + h->hid->set_layer = gpmi_hid_set_layer; + h->hid->set_color = gpmi_hid_set_color; + h->hid->set_line_cap = gpmi_hid_set_line_cap; + h->hid->set_line_width = gpmi_hid_set_line_width; + h->hid->set_draw_xor = gpmi_hid_set_draw_xor; + h->hid->set_draw_faded = gpmi_hid_set_draw_faded; + h->hid->draw_line = gpmi_hid_draw_line; + h->hid->draw_arc = gpmi_hid_draw_arc; + h->hid->draw_rect = gpmi_hid_draw_rect; + h->hid->fill_circle = gpmi_hid_fill_circle; + h->hid->fill_polygon = gpmi_hid_fill_polygon; + h->hid->fill_pcb_polygon = gpmi_hid_fill_pcb_polygon; + h->hid->fill_rect = gpmi_hid_fill_rect; + h->hid->fill_pcb_pv = gpmi_hid_fill_pcb_pv; + h->hid->use_mask = gpmi_hid_use_mask; + + h->attr_num = 0; + h->attr = NULL; + h->new_gc = NULL; + + hid_gpmi_data_set(h, h); + return h; +} + +dynamic char *hid_get_attribute(hid_t *hid, int attr_id) +{ + const char *res; + char buff[128]; + HID_Attr_Val *v; + + if ((hid == NULL) || (attr_id < 0) || (attr_id >= hid->attr_num) || (hid->result == NULL)) + return 0; + + res = NULL; + + v = &(hid->result[attr_id]); + switch(hid->type[attr_id]) { + case HIDA_Boolean: + if (v->int_value) + res = "true"; + else + res = "false"; + break; + case HIDA_Integer: + snprintf(buff, sizeof(buff), "%d", v->int_value); + res = buff; + break; + case HIDA_Real: + snprintf(buff, sizeof(buff), "%f", v->real_value); + res = buff; + break; + case HIDA_String: + case HIDA_Label: + case HIDA_Path: + res = v->str_value; + break; + case HIDA_Enum: + res = hid->attr[attr_id].enumerations[v->int_value]; +/* printf("res='%s' %d\n", res, v->int_value);*/ + break; + case HIDA_Coord: + pcb_sprintf(buff, "%mI", v->coord_value); + res = buff; + break; + case HIDA_Unit: + { + const Unit *u; + double fact; + u = get_unit_by_idx(v->int_value); + if (u == NULL) + fact = 0; + else + fact = unit_to_factor(u); + snprintf(buff, sizeof(buff), "%f", fact); + res = buff; +/* fprintf(stderr, "unit idx: %d %p res='%s'\n", v->int_value, u, res);*/ + } + break; + case HIDA_Mixed: + default: + fprintf(stderr, "error: hid_string2val: can't handle type %d\n", hid->type[attr_id]); + + } + if (res == NULL) + return NULL; + return strdup(res); +} + + +HID_Attr_Val hid_string2val(const hid_attr_type_t type, const char *str) +{ + HID_Attr_Val v; + memset(&v, 0, sizeof(v)); + switch(type) { + case HIDA_Boolean: + if ((strcasecmp(str, "true") == 0) || (strcasecmp(str, "yes") == 0) || (strcasecmp(str, "1") == 0)) + v.int_value = 1; + else + v.int_value = 0; + break; + case HIDA_Integer: + v.int_value = atoi(str); + break; + case HIDA_Coord: + { + char *end; + double val; + val = strtod(str, &end); + while(isspace(*end)) end++; + if (*end != '\0') { + const Unit *u; + u = get_unit_struct(end); + if (u == NULL) { + Message("Invalid unit for HIDA_Coord in the script: '%s'\n", end); + v.coord_value = 0; + } + else + v.coord_value = unit_to_coord(u, val); + } + else + v.coord_value = val; + } + break; + case HIDA_Unit: + { + const Unit *u; + u = get_unit_struct(str); + if (u != NULL) + v.real_value = unit_to_factor(u); + else + v.real_value = 0; + } + break; + case HIDA_Real: + v.real_value = atof(str); + break; + case HIDA_String: + case HIDA_Label: + case HIDA_Enum: + case HIDA_Path: + v.str_value = strdup(str); + break; + case HIDA_Mixed: + default: + fprintf(stderr, "error: hid_string2val: can't handle type %d\n", type); + } + return v; +} + +char **hid_string2enum(const char *str, HID_Attr_Val *def) +{ + char **e; + const char *s, *last; + int n, len; + + for(n=0, s=str; *s != '\0'; s++) + if (*s == '|') + n++; + e = malloc(sizeof(char *) * (n+2)); + + def->int_value = 0; + def->str_value = NULL; + def->real_value = 0.0; + + for(n = 0, last=s=str;; s++) { + + if ((*s == '|') || (*s == '\0')) { + if (*last == '*') { + def->int_value = n; + last++; + } + len = s - last; + e[n] = malloc(len+1); + if (len != 0) + strncpy(e[n], last, len); + e[n][len] = '\0'; + last = s+1; + n++; + } + if (*s == '\0') + break; + } + e[n] = NULL; + return e; +} + +int hid_add_attribute(hid_t *hid, char *attr_name, char *help, hid_attr_type_t type, int min, int max, char *default_val) +{ + int current = hid->attr_num; + + /* TODO: should realloc more space here */ + hid->attr_num++; + hid->attr = realloc(hid->attr, sizeof(HID_Attribute) * hid->attr_num); + hid->type = realloc(hid->type, sizeof(hid_attr_type_t) * hid->attr_num); + + hid->attr[current].name = strdup(attr_name); + hid->attr[current].help_text = strdup(help); + hid->attr[current].type = type; + hid->attr[current].min_val = min; + hid->attr[current].max_val = max; + if (type == HIDA_Unit) { + const Unit *u, *all; + all = get_unit_list(); + u = get_unit_struct(default_val); + if (u != NULL) + hid->attr[current].default_val.int_value = u-all; + else + hid->attr[current].default_val.int_value = -1; + } + else if (type == HIDA_Enum) { + hid->attr[current].enumerations = (const char **)hid_string2enum(default_val, &(hid->attr[current].default_val)); + } + else { + hid->attr[current].default_val = hid_string2val(type, default_val); + hid->attr[current].enumerations = NULL; + } + hid->attr[current].hash = 0; + + hid->type[current] = type; + + return current; +} + +static void cleanup_hid_reg(gpmi_module *mod, gpmi_cleanup *cl) +{ + hid_t *hid = cl->argv[0].p; + int n; + + hid_remove_hid(hid->hid); + + for(n = 0; n < hid->attr_num; n++) { + free(hid->attr[n].name); + free(hid->attr[n].help_text); + } + + if (hid->attr != NULL) + free(hid->attr); + if (hid->type != NULL) + free(hid->type); + + free((char *)hid->hid->name); + free((char *)hid->hid->description); + free(hid->hid); + free(hid); +} + +int hid_register(hid_t *hid) +{ + hid_register_hid(hid->hid); + + gpmi_mod_cleanup_insert(NULL, cleanup_hid_reg, "p", hid); + + return 0; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid.h (revision 1068) @@ -0,0 +1,86 @@ +#include + +/* Type of an HID attribute (usually a widget on an attribute dialog box) */ +typedef enum hid_attr_type_e { + HIDA_Label, /* non-editable label displayed on the GUI */ + HIDA_Integer, /* a sugned integer value */ + HIDA_Real, /* a floating point value */ + HIDA_String, /* one line textual input */ + HIDA_Boolean, /* true/false boolean value */ + HIDA_Enum, /* select an item of a predefined list */ + HIDA_Mixed, /* TODO */ + HIDA_Path, /* path to a file or directory */ + HIDA_Unit, /* select a dimension unit */ + HIDA_Coord /* enter a coordinate */ +} hid_attr_type_t; + +gpmi_keyword *kw_hid_attr_type_e; /* of hid_attr_type_t */ + +/* TODO: these should not be here; GPMI needs to switch over to c99tree! */ +#ifndef FROM_PKG +typedef void HID; +typedef void HID_Attribute; +typedef void* hidGC; +typedef char* HID_Attr_Val; + +/* Line or arc ending style */ +typedef enum EndCapStyle_e { + Trace_Cap, /* filled circle (trace drawing) */ + Square_Cap, /* rectangular lines (square pad) */ + Round_Cap, /* round pins or round-ended pads, thermals */ + Beveled_Cap /* octagon pins or bevel-cornered pads */ +} EndCapStyle; + +typedef void *PolygonType; +typedef void *BoxType; +#endif + +typedef struct hid_s { + gpmi_module *module; + int attr_num; + HID_Attribute *attr; + hid_attr_type_t *type; + HID *hid; + HID_Attr_Val *result; + hidGC new_gc; +} hid_t; + +/* Creates a new hid context. Name and description matters only if the hid is +registered as an exporter later. */ +hid_t *hid_create(char *hid_name, char *description); + +/* Append an attribute in a hid previously created using hid_create(). + Arguments: + hid: hid_t previously created using hid_create() + attr_name: name of the attribute + help: help text for the attribute + type: type of the attribute (input widget type) + min: minimum value of the attribute, if type is integer or real) + max: maximum value of the attribute, if type is integer or real) + default_val: default value of the attribute + Returns an unique ID of the attribute the caller should store for + later reference. For example this ID is used when retrieving the + value of the attribute after the user finished entering data in + the dialog. */ +int hid_add_attribute(hid_t *hid, char *attr_name, char *help, hid_attr_type_t type, int min, int max, char *default_val); + +/* Query an attribute from the hid after dialog_attributes() returned. + Arguments: + hid: hid_t previously created using hid_create() + attr_id: the unique ID of the attribute (returned by hid_add_attribute()) + Returns the value (converted to string) set by the user. */ +dynamic char *hid_get_attribute(hid_t *hid, int attr_id); + +/* Register the hid; call it after a hid is created and its attributes + are all set up */ +int hid_register(hid_t *hid); + +/* For internal use */ +void hid_gpmi_data_set(hid_t *h, void *data); + +/* For internal use */ +hid_t *hid_gpmi_data_get(HID *h); + +/* For internal use */ +nowrap HID_Attr_Val hid_string2val(const hid_attr_type_t type, const char *str); + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.c (revision 1068) @@ -0,0 +1,172 @@ +#include +#include "src/global.h" +#include "src/hid.h" +#include "src/data.h" +#include "src/hid/hidint.h" +#define FROM_PKG +#include "hid.h" +#include "hid_events.h" +#include "hid_callbacks.h" + +/* TODO */ +#define MAX_LAYER 16 + +HID_Attribute *gpmi_hid_get_export_options(int *num) +{ + hid_t *h; + + h = hid_gpmi_data_get(exporter); + + if (h == NULL) + return NULL; + + gpmi_event(h->module, HIDE_get_export_options, h); + + if (num != NULL) + *num = h->attr_num; + return h->attr; +} + +static char *gcs = "abcdefghijklmnopqrstuvxyz"; +hidGC gpmi_hid_make_gc(void) +{ + hidGC ret; + hid_t *h = hid_gpmi_data_get(exporter); + + /* TODO: fix gc handling... */ + h->new_gc = (void *)(gcs++); + gpmi_event(h->module, HIDE_make_gc, h, h->new_gc); + ret = h->new_gc; + h->new_gc = NULL; + return ret; +} + +void gpmi_hid_destroy_gc(hidGC gc) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_destroy_gc, h, gc); +} + +void gpmi_hid_do_export(HID_Attr_Val * options) +{ + hid_t *h = hid_gpmi_data_get(exporter); + int save_ons[MAX_LAYER + 2]; + BoxType region; + + h->result = options; + gpmi_event(h->module, HIDE_do_export_start, h); + + hid_save_and_show_layer_ons(save_ons); + + region.X1 = 0; + region.Y1 = 0; + region.X2 = PCB->MaxWidth; + region.Y2 = PCB->MaxHeight; + + hid_expose_callback(h->hid, ®ion, 0); + hid_restore_layer_ons(save_ons); + gpmi_event(h->module, HIDE_do_export_finish, h); + h->result = NULL; +} + +void gpmi_hid_parse_arguments(int *pcbargc, char ***pcbargv) +{ + /* Do nothing for now */ + hid_parse_command_line(pcbargc, pcbargv); +} + +void gpmi_hid_set_crosshair(int x, int y, int cursor_action) +{ + /* Do nothing */ +} + +int gpmi_hid_set_layer(const char *name, int group, int empty) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_layer, h, name, group, empty); + return 1; +} + +void gpmi_hid_set_color(hidGC gc, const char *name) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_color, h, gc, name); +} + +void gpmi_hid_set_line_cap(hidGC gc, EndCapStyle style) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_line_cap, h, gc, style); +} + +void gpmi_hid_set_line_width(hidGC gc, Coord width) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_line_width, h, gc, width); +} + +void gpmi_hid_set_draw_xor(hidGC gc, int xor) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_draw_xor, h, gc, xor); +} + +void gpmi_hid_set_draw_faded(hidGC gc, int faded) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_set_draw_faded, h, gc, faded); +} + +void gpmi_hid_draw_line(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_draw_line, h, gc, x1, y1, x2, y2); +} + +void gpmi_hid_draw_arc(hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_draw_arc, h, gc, cx, cy, xradius, yradius, start_angle, delta_angle); +} + +void gpmi_hid_draw_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_draw_rect, h, gc, x1, y1, x2, y2); +} + +void gpmi_hid_fill_circle(hidGC gc, Coord cx, Coord cy, Coord radius) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_fill_circle, h, gc, cx, cy, radius); +} + +void gpmi_hid_fill_polygon(hidGC gc, int n_coords, Coord *x, Coord *y) +{ + hid_t *h = hid_gpmi_data_get(exporter); + /* TODO: need accessor for these */ + gpmi_event(h->module, HIDE_fill_polygon, h, gc, x, y); +} + +void gpmi_hid_fill_pcb_polygon(hidGC gc, PolygonType *poly, const BoxType *clip_box) +{ + /* TODO */ +} + +void gpmi_hid_fill_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_fill_rect, h, gc, x1, y1, x2, y2); +} + +void gpmi_hid_use_mask(int use_it) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_use_mask, h, use_it); +} + +void gpmi_hid_fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask) +{ + hid_t *h = hid_gpmi_data_get(exporter); + gpmi_event(h->module, HIDE_fill_pcb_pv, h, fg_gc, bg_gc, pad, drawHole, mask); +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_callbacks.h (revision 1068) @@ -0,0 +1,21 @@ +HID_Attribute *gpmi_hid_get_export_options(int *num); +hidGC gpmi_hid_make_gc(void); +void gpmi_hid_destroy_gc(hidGC gc); +void gpmi_hid_do_export(HID_Attr_Val * options); +void gpmi_hid_parse_arguments(int *pcbargc, char ***pcbargv); +void gpmi_hid_set_crosshair(int x, int y, int cursor_action); +int gpmi_hid_set_layer(const char *name, int group, int _empty); +void gpmi_hid_set_color(hidGC gc, const char *name); +void gpmi_hid_set_line_cap(hidGC gc, EndCapStyle style); +void gpmi_hid_set_line_width(hidGC gc, Coord width); +void gpmi_hid_set_draw_xor(hidGC gc, int xor); +void gpmi_hid_set_draw_faded(hidGC gc, int faded); +void gpmi_hid_draw_line(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); +void gpmi_hid_draw_arc(hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle); +void gpmi_hid_draw_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); +void gpmi_hid_fill_circle(hidGC gc, Coord cx, Coord cy, Coord radius); +void gpmi_hid_fill_polygon(hidGC gc, int n_coords, Coord *x, Coord *y); +void gpmi_hid_fill_pcb_polygon(hidGC gc, PolygonType *poly, const BoxType *clip_box); +void gpmi_hid_fill_rect(hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2); +void gpmi_hid_fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pad, bool drawHole, bool mask); +void gpmi_hid_use_mask(int use_it); Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/hid/hid_events.h (revision 1068) @@ -0,0 +1,60 @@ +/*********** Exporter events ************/ + +/* Called before get_exporter_options returns the option list to the GUI hid */ +gpmi_define_event(HIDE_get_export_options)(void *hid); + +/* Called before export redraw starts */ +gpmi_define_event(HIDE_do_export_start)(void *hid); + +/* Called after export redraw finihsed */ +gpmi_define_event(HIDE_do_export_finish)(void *hid); + +/* DRAWING */ + +/* PCB callback events for drawing: change layer */ +gpmi_define_event(HIDE_set_layer)(void *hid, const char *name, int group, int empty); + +/* PCB callback events for drawing: change drawing color */ +gpmi_define_event(HIDE_set_color)(void *hid, void *gc, const char *name); + +/* PCB callback events for drawing: change drawing line cap style*/ +gpmi_define_event(HIDE_set_line_cap)(void *hid, void *gc, EndCapStyle style); + +/* PCB callback events for drawing: change drawing line width */ +gpmi_define_event(HIDE_set_line_width)(void *hid, void *gc, int width); + +/* PCB callback events for drawing: toggle xor drawing method */ +gpmi_define_event(HIDE_set_draw_xor)(void *hid, void *gc, int xor); + +/* PCB callback events for drawing: toggle faded drawing method */ +gpmi_define_event(HIDE_set_draw_faded)(void *hid, void *gc, int faded); + +/* PCB callback events for drawing: draw a line */ +gpmi_define_event(HIDE_draw_line)(void *hid, void *gc, int x1, int y1, int x2, int y2); + +/* PCB callback events for drawing: draw an arc from center cx;cy */ +gpmi_define_event(HIDE_draw_arc)(void *hid, void *gc, int cx, int cy, int xradius, int yradius, double start_angle, double delta_angle); + +/* PCB callback events for drawing: draw a rectangle */ +gpmi_define_event(HIDE_draw_rect)(void *hid, void *gc, int x1, int y1, int x2, int y2); + +/* PCB callback events for drawing: draw a filled circle */ +gpmi_define_event(HIDE_fill_circle)(void *hid, void *gc, int cx, int cy, int radius); + +/* PCB callback events for drawing: draw a filled ploygon */ +gpmi_define_event(HIDE_fill_polygon)(void *hid, void *gc, int n_coords, int *x, int *y); + +/* PCB callback events for drawing: draw a filled rectangle */ +gpmi_define_event(HIDE_fill_rect)(void *hid, void *gc, int x1, int y1, int x2, int y2); + +/* PCB callback events for drawing: TODO */ +gpmi_define_event(HIDE_use_mask)(void *hid, int use_it); + +/* PCB callback events for drawing: create a new graphical context */ +gpmi_define_event(HIDE_make_gc)(void *hid, void *gc); + +/* PCB callback events for drawing: destroy a graphical context */ +gpmi_define_event(HIDE_destroy_gc)(void *hid, void *gc); + +/* PCB callback events for drawing: TODO */ +gpmi_define_event(HIDE_fill_pcb_pv)(void *hid, void *fg_gc, void *bg_gc, void *pad, int drawHole, int mask); Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.am (revision 1068) @@ -0,0 +1,20 @@ +# This file is package-specific. Do include it in the distribution. +# +# GPMI fingerprint: Makefile.am.ext-pkg + +# End INST_PATH with / +INST_PATH = pcb-gpmi/ +FILE_NAME = layout + +SOURCE = search.c +SOURCE += object.c +SOURCE += create.c +SOURCE += layers.c +SOURCE += page.c + +HEADER = layout.h + +PKG_LDFLAGS = + +include ../../../Makefile.config +INCLUDES = -I $(PCB_SRC) Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/Makefile.dep (revision 1068) @@ -0,0 +1 @@ +#Please run make depend! Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/coord.c (revision 1068) @@ -0,0 +1,20 @@ +#include "layout.h" +#include "src/pcb-printf.h" + +double mil2pcb_multiplier() +{ + return 10000.0*2.54; +} + +double mm2pcb_multiplier() +{ + return 1000000.0; +} + +const char *current_grid_unit() +{ + const Unit *u = Settings.grid_unit; + if (u == NULL) + return ""; + return u->suffix; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/create.c (revision 1068) @@ -0,0 +1,112 @@ +#include +#include +#include "layout.h" +#include "src/undo.h" + + +typedef struct flag_tr_s { + int flag; /* flag or thermal */ + int gpmi, pcb; +} flag_tr_t; + +static flag_tr_t flags[] = { + {1, FL_SHOWNUMBER, SHOWNUMBERFLAG}, + {1, FL_LOCALREF, LOCALREFFLAG}, + {1, FL_CHECKPLANS, CHECKPLANESFLAG}, + {1, FL_SHOWDRC, SHOWDRCFLAG}, + {1, FL_RUBBERBAND, RUBBERBANDFLAG}, + {1, FL_DESCRIPTION, DESCRIPTIONFLAG}, + {1, FL_NAMEONPCB, NAMEONPCBFLAG}, + {1, FL_AUTODRC, AUTODRCFLAG}, + {1, FL_ALLDIRECTION, ALLDIRECTIONFLAG}, + {1, FL_SWAPSTARTDIR, SWAPSTARTDIRFLAG}, + {1, FL_UNIQUENAME, UNIQUENAMEFLAG}, + {1, FL_CLEARNEW, CLEARNEWFLAG}, + {1, FL_SNAPPIN, SNAPPINFLAG}, + {1, FL_SHOWMASK, SHOWMASKFLAG}, + {1, FL_THINDRAW, THINDRAWFLAG}, + {1, FL_ORTHOMOVE, ORTHOMOVEFLAG}, + {1, FL_LIVEROUTE, LIVEROUTEFLAG}, + {1, FL_THINDRAWPOLY, THINDRAWPOLYFLAG}, + {1, FL_LOCKNAMES, LOCKNAMESFLAG}, + {1, FL_ONLYNAMES, ONLYNAMESFLAG}, + {1, FL_NEWFULLPOLY, NEWFULLPOLYFLAG}, + {1, FL_HIDENAMES, HIDENAMESFLAG}, + + {0, FL_THERMALSTYLE1, 1}, + {0, FL_THERMALSTYLE2, 2}, + {0, FL_THERMALSTYLE3, 3}, + {0, FL_THERMALSTYLE4, 4}, + {0, FL_THERMALSTYLE5, 5}, + {0, 0, 0} +}; + +static FlagType get_flags(int in) +{ + flag_tr_t *f; + static FlagType out; + + out.f = 0; + memset(out.t, 0, sizeof(out.t)); + for(f = flags; f->gpmi != 0; f++) { + if (in & f->gpmi) { + if (f->flag) + out.f |= f->pcb; + else + memset(out.t, f->pcb, sizeof(out.t)); + } + } + return out; +} + +static void *layout_create_line_(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags) +{ + void *line; + + line = CreateNewLineOnLayer (CURRENT, x1, y1, x2, y2, thickness, clearance, get_flags(flags)); + if (line != NULL) { + AddObjectToCreateUndoList (LINE_TYPE, CURRENT, line, line); + return line; + } + return NULL; +} + +int layout_create_line(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags) +{ + return layout_create_line_(x1, y1, x2, y2, thickness, clearance, flags) != NULL; +} + +static void *layout_create_via_(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags) +{ + void *pin; + + pin = CreateNewVia (PCB->Data, x, y, thickness, clearance, mask, hole, name, get_flags(flags)); + + if (pin != NULL) { + AddObjectToCreateUndoList (VIA_TYPE, pin, pin, pin); + return pin; + } + return NULL; +} + +int layout_create_via(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags) +{ + return layout_create_via_(x, y, thickness, clearance, mask, hole, name, flags) != NULL; +} + +static void *layout_create_arc_(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags) +{ + void *arc; + arc = CreateNewArcOnLayer (CURRENT, x, y, width, height, sa, dir, thickness, clearance, get_flags(flags)); + if (arc != NULL) { + AddObjectToCreateUndoList (ARC_TYPE, CURRENT, arc, arc); + return 0; + } + return NULL; +} + +int layout_create_arc(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags) +{ + return layout_create_arc_(x, y, width, height, sa, dir, thickness, clearance, flags) != NULL; +} + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/debug_draw.c (revision 1068) @@ -0,0 +1,49 @@ +#include +#include +#include "layout.h" +#include "src/hid.h" +#include "src/error.h" + +static HID *ddh = NULL; + +#define need_ddh if (ddh == NULL) return + + +int debug_draw_request(void) +{ + ddh = gui->request_debug_draw(); + if (ddh == NULL) + return 0; + return 1; +} + +void debug_draw_flush(void) +{ + need_ddh; + gui->flush_debug_draw(); +} + +void debug_draw_finish(dctx_t *ctx) +{ + need_ddh; + ddh->destroy_gc(ctx->gc); + gui->finish_debug_draw(); + free(ctx); + ddh = NULL; +} + +dctx_t *debug_draw_dctx(void) +{ + dctx_t *ctx; + hidGC gc; + need_ddh(NULL); + gc = ddh->make_gc(); + if (gc == NULL) { + Message("debug_draw_dctx(): failed to make a new gc on ddh %p\n", ddh); + return NULL; + } + + ctx = malloc(sizeof(dctx_t)); + ctx->hid = ddh; + ctx->gc = gc; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/draw.c (revision 1068) @@ -0,0 +1,45 @@ +#include +#include +#include "layout.h" +#include "src/hid.h" +#include "src/error.h" + +#define setup \ + hidGC gc = ctx->gc; \ + HID *hid = ctx->hid; \ + if ((hid == NULL) && (gc == NULL)) Message("%s failed because of invalid hid or gc\n", __FUNCTION__); \ + if ((hid == NULL) && (gc == NULL)) return + + +void draw_set_color(dctx_t *ctx, const char *name) +{ + setup; + hid->set_color(gc, name); +} + +/*void set_line_cap(dctx_t *ctx, EndCapStyle style_);*/ +void draw_set_line_width(dctx_t *ctx, int width) +{ + setup; + hid->set_line_width(gc, width); +} + +void draw_set_draw_xor(dctx_t *ctx, int xor) +{ + setup; + hid->set_draw_xor(gc, xor); +} + + +void draw_set_draw_faded(dctx_t *ctx, int faded) +{ + setup; + hid->set_draw_faded(gc, faded); +} + +void draw_line(dctx_t *ctx, int x1, int y1, int x2, int y2) +{ + setup; + hid->draw_line(gc, x1, y1, x2, y2); +} + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/gpmi.conf (revision 1068) @@ -0,0 +1,18 @@ +@/local/headers + layout.h + +@/local/srcs + create.c layers.c object.c page.c search.c coord.c debug_draw.c draw.c + +@/local/file_name + layout + +@/local/inst_path + layout + +@/local/CFLAGS + -I.. -I$(PCB_SRC) $(PCB_CFLAGS) -D###/target/sys/class### + +@@/local/hook/postall + PCB_GPMI_ROOT=../../.. + include $(PCB_GPMI_ROOT)/Makefile.config Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layers.c (revision 1068) @@ -0,0 +1,75 @@ +#include +#include +#include "layout.h" +#include "src/misc.h" +#include "src/draw.h" + +#define layer_check(layer) \ + if ((layer < 0) || (layer >= MAX_LAYER+2)) \ + return + + +void layout_switch_to_layer(int layer) +{ + layer_check(layer); + ChangeGroupVisibility(layer, true, true); + Redraw(); +} + +int layout_get_current_layer() +{ + return GetLayerNumber(PCB->Data, CURRENT); +} + +int layout_resolve_layer(const char *name) +{ + int n; + if (name == NULL) + return -2; + for(n = 0; n < MAX_LAYER + 2; n++) + if ((PCB->Data->Layer[n].Name != NULL) && (strcmp(PCB->Data->Layer[n].Name, name) == 0)) + return n; + return -1; +} + +int layout_get_max_possible_layer() +{ + return MAX_LAYER+2; +} + +int layout_get_max_copper_layer() +{ + return max_copper_layer; +} + +int layout_get_max_layer() +{ + return max_copper_layer+2; +} + + +const char *layout_layer_name(int layer) +{ + layer_check(layer)(""); + return PCB->Data->Layer[layer].Name; +} + +const char *layout_layer_color(int layer) +{ + layer_check(layer)(""); + return PCB->Data->Layer[layer].Color; +} + +int layout_layer_field(int layer, layer_field_t fld) +{ + layer_check(layer)(-1); + switch(fld) { + case LFLD_NUM_LINES: return PCB->Data->Layer[layer].LineN; + case LFLD_NUM_TEXTS: return PCB->Data->Layer[layer].TextN; + case LFLD_NUM_POLYS: return PCB->Data->Layer[layer].PolygonN; + case LFLD_NUM_ARCS: return PCB->Data->Layer[layer].ArcN; + case LFLD_VISIBLE: return PCB->Data->Layer[layer].On; + case LFLD_NODRC: return PCB->Data->Layer[layer].no_drc; + } + return -1; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/layout.h (revision 1068) @@ -0,0 +1,262 @@ +#include +#include "src/global.h" +#include "src/rtree.h" +#include "src/create.h" +#include "src/data.h" + +/* Object type search mask bits */ +typedef enum layout_object_mask_e { + OM_LINE = 1, /* lines (traces, silk lines, not font) */ + OM_TEXT = 2, /* text written using the font */ + OM_POLYGON = 4, /* polygons, including rectangles */ + OM_ARC = 8, /* arcs, circles */ + OM_VIA = 16, /* vias and holes which are not part of a footprint */ + OM_PIN = 32, /* pins/pads of a footprint */ + + OM_ANY = 0xffff /* shorthand for "find anything" */ +} layout_object_mask_t; +gpmi_keyword *kw_layout_object_mask_e; /* of layout_object_mask_t */ + +/* Which coordinate of the object is referenced */ +typedef enum layout_object_coord_e { +/* X/Y coords */ + OC_BX1 = 1, /* bounding box X1 */ + OC_BX2 = 2, /* bounding box X2 */ + OC_BY1 = 3, /* bounding box Y1 */ + OC_BY2 = 4, /* bounding box Y2 */ + OC_P1X = 5, /* point 1 X */ + OC_P2X = 6, /* point 2 X */ + OC_P1Y = 7, /* point 1 Y */ + OC_P2Y = 8, /* point 2 Y */ + OC_OBJ = 9, /* the whole object */ + +/* point aliases for X/Y coords */ + OC_P1 = 5, /* point 1 is P1X*/ + OC_P2 = 6 /* point 2 is P2X */ + +} layout_object_coord_t; +gpmi_keyword *kw_layout_object_coord_e; /* of layout_object_coord_t */ + + +typedef enum layout_flag_e { + FL_NONE = 0, + FL_SHOWNUMBER = 0x00000001, + FL_LOCALREF = 0x00000002, + FL_CHECKPLANS = 0x00000004, + FL_SHOWDRC = 0x00000008, + FL_RUBBERBAND = 0x00000010, + FL_DESCRIPTION = 0x00000020, + FL_NAMEONPCB = 0x00000040, + FL_AUTODRC = 0x00000080, + FL_ALLDIRECTION = 0x00000100, + FL_SWAPSTARTDIR = 0x00000200, + FL_UNIQUENAME = 0x00000400, + FL_CLEARNEW = 0x00000800, + FL_SNAPPIN = 0x00001000, + FL_SHOWMASK = 0x00002000, + FL_THINDRAW = 0x00004000, + FL_ORTHOMOVE = 0x00008000, + FL_LIVEROUTE = 0x00010000, + FL_THINDRAWPOLY = 0x00020000, + FL_LOCKNAMES = 0x00040000, + FL_ONLYNAMES = 0x00080000, + FL_NEWFULLPOLY = 0x00100000, + FL_HIDENAMES = 0x00200000, + + FL_THERMALSTYLE1 = 0x08000000, + FL_THERMALSTYLE2 = 0x10000000, + FL_THERMALSTYLE3 = 0x20000000, + FL_THERMALSTYLE4 = 0x40000000, + FL_THERMALSTYLE5 = 0x80000000 +} layout_flag_t; +gpmi_keyword *kw_layout_flag_e; /* of layout_flag_t */ + + + +typedef struct layout_object_s { + layout_object_mask_t type; + union { + LineType *l; + TextType *t; + PolygonType *p; + ArcType *a; + PinType *v; + PinType *pin; + } obj; + int layer; +} layout_object_t; + + +typedef struct layout_search_s { + layout_object_mask_t searching; /* during the search, this field is used to communicate with the callback */ + int used, alloced; + layout_object_t *objects; + int layer; +} layout_search_t; + +/* -- search -- (search.c) */ +/* creates a new search and adds all objects that matches obj_types mask within the given rectangle on the current layer + Arguments: + search_ID: unique name of the search (overwrites existing search on the same name) + obj_types: on or more object types + x1, y1, x2, y2: box the search is done within (PCB coords) + Returns the number of object on the search list. */ +int layout_search_box(const char *search_ID, layout_object_mask_t obj_types, int x1, int y1, int x2, int y2); + +/* creates a new search and adds all selected objects + Arguments: + search_ID: unique name of the search (overwrites existing search on the same name) + obj_types: on or more object types + Returns the number of object on the search list. */ +int layout_search_selected(const char *search_ID, multiple layout_object_mask_t obj_types); + +/* creates a new search and adds all found objects (the green highlight) + Arguments: + search_ID: unique name of the search (overwrites existing search on the same name) + obj_types: on or more object types + Returns the number of object on the search list. */ +int layout_search_found(const char *search_ID, multiple layout_object_mask_t obj_types); + +/* Returns the nth object from a search list (or NULL pointer if n is beyond the list) */ +layout_object_t *layout_search_get(const char *search_ID, int n); + +/* Frees all memory related to a search. Returns 0 on success. + Argument: + search_ID: unique name of the search (requires an existing search) */ +int layout_search_free(const char *search_ID); + +/* -- object accessors -- (object.c) */ +/* Return the requested coord of an object; except for the bounding box + coordinates, the meaning of coordinates are object-specific. + Point 1 and point 2 are usually endpoints of the object (line, arc), + "the whole object" coordinate is a central point. */ +int layout_obj_coord(layout_object_t *obj, layout_object_coord_t coord); + +/* Return the type of an object (always a single bit) */ +layout_object_mask_t layout_obj_type(layout_object_t *obj); + +/* Change location of an object or parts of the object (like move endpoint of a line); + Arguments: + obj: the object + coord: which coordinate to drag (e.g. move only the endpoint) + dx, dy: relative x and y coordinates the selected coordinate is displaced by + Returns 0 on success */ +int layout_obj_move(layout_object_t *obj, layout_object_coord_t coord, int dx, int dy); + +/* change angles of an arc; start and delate are relative if relative is non-zero; returns 0 on success */ +int layout_arc_angles(layout_object_t *obj, int relative, int start, int delta); + +/* -- create new objects -- (create.c) */ +/* create a line */ +int layout_create_line(int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags); + +/* same as layout_create_line(), but appends the result to a list and + returns the index of the new object on the list (can be used as n for + layour_search_get) +int layout_lcreate_line(const char *search_ID, int x1, int y1, int x2, int y2, int thickness, int clearance, multiple layout_flag_t flags);*/ + +/* create a named via */ +int layout_create_via(int x, int y, int thickness, int clearance, int mask, int hole, const char *name, multiple layout_flag_t flags); + +/* create a new arc; sa is start angle, dir is delta angle */ +int layout_create_arc(int x, int y, int width, int height, int sa, int dir, int thickness, int clearance, multiple layout_flag_t flags); + +/* -- layer manipulation -- (layers.c) */ +/* Field name of the layer structure */ +typedef enum layer_field_e { + LFLD_NUM_LINES, /* number of lines on the layer */ + LFLD_NUM_TEXTS, /* number of texts on the layer */ + LFLD_NUM_POLYS, /* number of polygons on the layer */ + LFLD_NUM_ARCS, /* number of arcs on the layer */ + LFLD_VISIBLE, /* non-zero if the layer is visible */ + LFLD_NODRC /* non-zero if the layer doesn't use DRC */ +} layer_field_t; + +/* switch to layer (further layer-specific actions will take place there) */ +void layout_switch_to_layer(int layer); + +/* returns the number of the current layer */ +int layout_get_current_layer(); + +/* resolve layer number by name (case sensitive); returns negative number if not found */ +int layout_resolve_layer(const char *name); + +/* return the theoretical number of layers supported by PCB */ +int layout_get_max_possible_layer(); + +/* return the actual number of copper layers on the current design */ +int layout_get_max_copper_layer(); + +/* return the actual number of layers on the current design */ +int layout_get_max_layer(); + +/* return the name of a layer */ +const char *layout_layer_name(int layer); + +/* return the color of a layer */ +const char *layout_layer_color(int layer); + +/* return an integer field of a layer */ +int layout_layer_field(int layer, layer_field_t fld); + + +/* -- page manipulation -- (page.c) */ +/* query or set width and height of the drawing */ +int layout_get_page_width(); +int layout_get_page_height(); +void layout_set_page_size(int width, int height); + +/* -- coordinate system -- (coord.c) */ +double mil2pcb_multiplier(); +double mm2pcb_multiplier(); +const char *current_grid_unit(); + +typedef struct dctx_s { + void *hid; + void *gc; +} dctx_t; + +/* -- debug draw GC -- */ +/* Initialize debug drawing; returns 1 if worked, 0 if denied */ +int debug_draw_request(void); + +/* Flush the drawing */ +void debug_draw_flush(void); + +/* Finish (close) drawing */ +void debug_draw_finish(dctx_t *ctx); + +/* Get the draw context of debug draw */ +dctx_t *debug_draw_dctx(void); + +/* -- draw on a GC -- */ + +/* Debug draw style: set drawing color */ +void draw_set_color(dctx_t *ctx, const char *name); +/*void set_line_cap(dctx_t *ctx, EndCapStyle style_);*/ + +/* Debug draw style: set line width */ +void draw_set_line_width(dctx_t *ctx, int width); + +/* Debug draw style: set whether drawing should happen in xor */ +void draw_set_draw_xor(dctx_t *ctx, int xor); + +/* Debug draw style: set whether drawing should happen in faded mode */ +void draw_set_draw_faded(dctx_t *ctx, int faded); + +/* Debug draw: draw a line using the current style settings */ +void draw_line(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); + +/* +void draw_arc(dctx_t *ctx, int cx_, int cy_, int xradius_, int yradius_, double start_angle_, double delta_angle_); +void draw_rect(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); +void fill_circle(dctx_t *ctx, int cx_, int cy_, int radius_); +void fill_polygon(dctx_t *ctx, int n_ints_, int *x_, int *y_); +void fill_pcb_polygon(dctx_t *ctx, PolygonType *poly, const BoxType *clip_box); +void thindraw_pcb_polygon(dctx_t *ctx, PolygonType *poly, const BoxType *clip_box); +void fill_pcb_pad(dctx_t *ctx, PadType *pad, bool clip, bool mask); +void thindraw_pcb_pad(dctx_t *ctx, PadType *pad, bool clip, bool mask); +void fill_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); +void thindraw_pcb_pv(hidGC fg_gc, hidGC bg_gc, PinType *pv, bool drawHole, bool mask); +void fill_rect(dctx_t *ctx, int x1_, int y1_, int x2_, int y2_); +*/ Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/object.c (revision 1068) @@ -0,0 +1,143 @@ +#include +#include +#include "layout.h" +#include "src/change.h" +#include "src/misc.h" +#include "src/move.h" + +int layout_obj_coord(layout_object_t *obj, layout_object_coord_t coord) +{ + AnyObjectType *o; + + if (obj == NULL) + return -1; + + o = (AnyObjectType *)obj->obj.l; + + /* bounding box is the same for any type */ + switch (coord) { + case OC_BX1: return o->BoundingBox.X1; + case OC_BX2: return o->BoundingBox.X2; + case OC_BY1: return o->BoundingBox.Y1; + case OC_BY2: return o->BoundingBox.Y2; + case OC_OBJ: return -1; + default: /* avoids warnings for unhandled requests we handle later, per object type */ + ; + } + + switch(obj->type) { + case OM_LINE: + switch (coord) { + case OC_P1X: return obj->obj.l->Point1.X; + case OC_P2X: return obj->obj.l->Point2.X; + case OC_P1Y: return obj->obj.l->Point1.Y; + case OC_P2Y: return obj->obj.l->Point2.Y; + default: /* avoids warnings for unhandled requests we handled above */ + ; + } + break; + case OM_TEXT: + switch (coord) { + case OC_P1X: + case OC_P2X: return obj->obj.t->X; + case OC_P1Y: + case OC_P2Y: return obj->obj.t->Y; + default: /* avoids warnings for unhandled requests we handled above */ + ; + } + break; + case OM_VIA: + switch (coord) { + case OC_P1X: + case OC_P2X: return obj->obj.v->X; + case OC_P1Y: + case OC_P2Y: return obj->obj.v->Y; + default: /* avoids warnings for unhandled requests we handled above */ + ; + } + break; + case OM_PIN: + switch (coord) { + case OC_P1X: + case OC_P2X: return obj->obj.pin->X; + case OC_P1Y: + case OC_P2Y: return obj->obj.pin->Y; + default: /* avoids warnings for unhandled requests we handled above */ + ; + } + break; + } + + return -1; +} + +layout_object_mask_t layout_obj_type(layout_object_t *obj) +{ + if (obj == NULL) + return 0; + return obj->type; +} + +int layout_obj_move(layout_object_t *obj, layout_object_coord_t coord, int dx, int dy) +{ + void *what = NULL;; + + if (obj == NULL) + return -1; + + switch(obj->type) { + case OM_LINE: + switch(coord) { + case OC_OBJ: + MoveObject (LINEPOINT_TYPE, CURRENT, obj->obj.l, &(obj->obj.l->Point2), dx, dy); + /* intended falltrough */ + case OC_P1X: + case OC_P1Y: what = &(obj->obj.l->Point1); break; + case OC_P2X: + case OC_P2Y: what = &(obj->obj.l->Point2); break; + default: /* we do not handle anything else for now */ + ; + } + MoveObject (LINEPOINT_TYPE, CURRENT, obj->obj.l, what, dx, dy); + return 0; + case OM_TEXT: + MoveObject (TEXT_TYPE, CURRENT, obj->obj.t, obj->obj.t, dx, dy); + return 0; + case OM_VIA: + MoveObject (VIA_TYPE, obj->obj.v, obj->obj.v, obj->obj.v, dx, dy); + return 0; + case OM_PIN: + MoveObject (PIN_TYPE, obj->obj.pin, obj->obj.pin, obj->obj.pin, dx, dy); + return 0; + case OM_ARC: + switch(coord) { + case OC_OBJ: + MoveObject (ARC_TYPE, CURRENT, obj->obj.a, obj->obj.a, dx, dy); + return 0; + default: /* we do not handle anything else for now */ + ; + } + /*TODO: move endpoints! */ + break; + case OM_POLYGON: + if (obj->layer != -1) { + MoveObject (POLYGON_TYPE, PCB->Data->Layer + obj->layer, obj->obj.p, obj->obj.p, dx, dy); + return 0; + } + } + return -1; +} + +int layout_arc_angles(layout_object_t *obj, int relative, int start, int delta) +{ + if (obj == NULL) + return -1; + if (obj->type != OM_ARC) + return 1; + if (relative) { + start += obj->obj.a->StartAngle; + delta += obj->obj.a->Delta; + } + ChangeArcAngles (CURRENT, obj->obj.a, start, delta); + return 0; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/page.c (revision 1068) @@ -0,0 +1,18 @@ +#include "layout.h" +#include "src/change.h" + +int layout_get_page_width() +{ + return PCB->MaxWidth; +} + +int layout_get_page_height() +{ + return PCB->MaxHeight; +} + +void layout_set_page_size(int width, int height) +{ + ChangePCBSize (MIN(MAX_COORD, MAX(width, MIN_SIZE)), MIN(MAX_COORD, MAX(height, MIN_SIZE))); +} + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_pkg/layout/search.c (revision 1068) @@ -0,0 +1,183 @@ +#include +#include +#include +#include +#include "layout.h" +#include "config.h" + +static inline void search_append(layout_search_t *s, void *obj) +{ + layout_object_t *o; + if (s->used >= s->alloced) { + s->alloced += 256; + s->objects = realloc(s->objects, s->alloced * sizeof(layout_object_t)); + } + o = s->objects + s->used; + s->used++; + o->type = s->searching; + o->layer = s->layer; + switch(s->searching) { + case OM_LINE: o->obj.l = obj; break; + case OM_TEXT: o->obj.t = obj; break; + case OM_POLYGON: o->obj.p = obj; break; + case OM_ARC: o->obj.a = obj; break; + case OM_VIA: o->obj.v = obj; break; + case OM_PIN: o->obj.pin = obj; break; + default: + assert(!"Unimplemented object type"); + } +} + +static int search_callback (const BoxType * b, void *cl) +{ + search_append(cl, (void *)b); + return 1; +} + +hash_t *layout_searches = NULL; +static layout_search_t *new_search(const char *search_ID) +{ + layout_search_t *s; + layout_search_free(search_ID); + + if (layout_searches == NULL) { + layout_searches = hash_create(64, gpmi_hash_ptr); + assert(layout_searches != NULL); + } + + s = calloc(sizeof(layout_search_t), 1); + + hash_store(layout_searches, search_ID, s); + return s; +} + +int layout_search_box(const char *search_ID, layout_object_mask_t obj_types, int x1, int y1, int x2, int y2) +{ + BoxType spot; + layout_search_t *s = new_search(search_ID); + + spot.X1 = x1; + spot.Y1 = y1; + spot.X2 = x2; + spot.Y2 = y2; + + s->layer = -1; + if (obj_types & OM_LINE) { + s->searching = OM_LINE; + r_search (CURRENT->line_tree, &spot, NULL, search_callback, s); + } + + if (obj_types & OM_TEXT) { + s->searching = OM_TEXT; + r_search (CURRENT->text_tree, &spot, NULL, search_callback, s); + } + + if (obj_types & OM_ARC) { + s->searching = OM_ARC; + r_search (CURRENT->arc_tree, &spot, NULL, search_callback, s); + } + + if (obj_types & OM_VIA) { + s->searching = OM_VIA; + r_search (PCB->Data->via_tree, &spot, NULL, search_callback, s); + } + + if (obj_types & OM_PIN) { + s->searching = OM_PIN; + r_search (PCB->Data->pin_tree, &spot, NULL, search_callback, s); + } + + if (obj_types & OM_POLYGON) { + s->searching = OM_POLYGON; + for (s->layer = 0; s->layer < MAX_LAYER + 2; s->layer++) + r_search (PCB->Data->Layer[s->layer].polygon_tree, &spot, NULL, search_callback, s); + s->layer = -1; + } + + return s->used; +} + +/* SELECTEDFLAG */ + +typedef struct { + int flag; + layout_search_t *search; +} select_t; + +static void select_cb(void *obj_, void *ud) +{ + select_t *ctx = ud; + AnyObjectTypePtr obj = obj_; + if (TEST_FLAG(ctx->flag, obj)) + search_append(ctx->search, obj); +} + +#define select(s, om, flag, lst) \ + do { \ + select_t ctx; \ + ctx.flag = flag; \ + ctx.search = s; \ + s->searching = om; \ + g_list_foreach(lst, select_cb, &ctx); \ + s->searching = 0; \ + } while(0) + +static int layout_search_flag(const char *search_ID, multiple layout_object_mask_t obj_types, int flag) +{ + Cardinal l, n; + layout_search_t *s = new_search(search_ID); + LayerType *layer = PCB->Data->Layer; + + for (l =0; l < MAX_LAYER + 2; l++, layer++) { + s->layer = l; + select(s, OM_ARC, flag, layer->Arc); + select(s, OM_LINE, flag, layer->Line); + select(s, OM_TEXT, flag, layer->Text); + select(s, OM_POLYGON, flag, layer->Polygon); + } + select(s, OM_VIA, flag, PCB->Data->Via); +/* select(s, OM_PIN, flag, PCB->Data->Pin, PCB->Data->PinN); /* TODO */ + + return s->used; +} +#undef select + +int layout_search_selected(const char *search_ID, multiple layout_object_mask_t obj_types) +{ + return layout_search_flag(search_ID, obj_types, SELECTEDFLAG); +} + +int layout_search_found(const char *search_ID, multiple layout_object_mask_t obj_types) +{ + return layout_search_flag(search_ID, obj_types, FOUNDFLAG); +} + +layout_object_t *layout_search_get(const char *search_ID, int n) +{ + const layout_search_t *s; + + s = hash_find(layout_searches, search_ID); + +/* printf("s=%p\n", s);*/ + if ((s == NULL) || (n < 0) || (n >= s->used)) + return NULL; + return s->objects+n; +} + +int layout_search_free(const char *search_ID) +{ + layout_search_t *s; + + if (layout_searches == NULL) + return 1; + + s = (layout_search_t *)hash_find(layout_searches, search_ID); + if (s != NULL) { + hash_del_key(layout_searches, search_ID); + free(s->objects); + free(s); + return 0; + } + return 2; +} + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.c (revision 1068) @@ -0,0 +1,218 @@ +#include +#include +#include +#include +#include +#include "src/misc.h" +#include "src/event.h" +#include "src/paths.h" +#include "src/error.h" +#include "scripts.h" +#include "manage_scripts.h" + +extern char *homedir; /* detected by pcn-rnd in InitPaths() */ + +/* This function is used to print a detailed GPMI error message */ +void gpmi_hid_print_error(gpmi_err_stack_t *entry, char *string) +{ + Message("[GPMI] %s\n", string); +} + + +int gpmi_hid_gui_inited = 0; +static void ev_gui_init(void *user_data, int argc, event_arg_t *argv[]) +{ + int ev; + char *ev_args; + hid_gpmi_script_info_t *i; + const char *menu[] = {"Plugins", "GPMI scripting", "Scripts", NULL}; + + gui->create_menu(menu, "gpmi_scripts()", "S", "Altg", "Manage GPMI scripts"); + + ev = gpmi_event_find("ACTE_gui_init", &ev_args); + if (ev >= 0) { + for(i = hid_gpmi_script_info; i != NULL; i = i->next) + if (i->module != NULL) + gpmi_event(i->module, ev, argc, argv); + } + gpmi_hid_gui_inited = 1; +} + +static void cmd_reload(char *name) +{ + hid_gpmi_script_info_t *i; + if (name != NULL) { + i = hid_gpmi_lookup(name); + if (i != NULL) + hid_gpmi_reload_module(i); + else + Message("Script %s not found\n", name); + } + else { + for(i = hid_gpmi_script_info; i != NULL; i = i->next) + hid_gpmi_reload_module(i); + } +} + +static int action_gpmi_scripts(int argc, char **argv, Coord x, Coord y) +{ + if (argc == 0) { + gpmi_hid_manage_scripts(); + return 0; + } + if (strcasecmp(argv[0], "reload") == 0) { + if (argc > 1) + cmd_reload(argv[1]); + else + cmd_reload(NULL); + } + else if (strcasecmp(argv[0], "load") == 0) { + if (argc == 3) { + if (hid_gpmi_load_module(NULL, argv[1], argv[2], NULL) == NULL) + Message("Failed to load %s %s\n", argv[1], argv[2]); + } + else + Message("Invalid number of arguments for load\n"); + } + else if (strcasecmp(argv[0], "unload") == 0) { + if (argc == 2) { + hid_gpmi_script_info_t *i = hid_gpmi_lookup(argv[1]); + if (i != NULL) { + if (gpmi_hid_script_unload(i) != 0) { + Message("Failed to unload %s\n", argv[1]); + return 1; + } + } + else { + Message("Failed to unload %s: not loaded\n", argv[1]); + return 1; + } + } + else { + Message("Invalid number of arguments for unload\n"); + return 1; + } + } + else { + Message("Invalid arguments in gpmi_scripts()\n"); + return 1; + } + return 0; +} + +static int action_gpmi_rehash(int argc, char **argv, Coord x, Coord y) +{ + cmd_reload(NULL); + return 0; +} + +static void register_actions() +{ + HID_Action *ctx; + + ctx = malloc(sizeof(HID_Action)); + ctx->name = strdup("gpmi_scripts"); + ctx->need_coord_msg = NULL; + ctx->description = strdup("Manage gpmi scripts"); + ctx->syntax = strdup("TODO"); + ctx->trigger_cb = action_gpmi_scripts; + + hid_register_action(ctx); + + ctx = malloc(sizeof(HID_Action)); + ctx->name = strdup("rehash"); + ctx->need_coord_msg = NULL; + ctx->description = strdup("Reload all gpmi scripts"); + ctx->syntax = strdup("TODO"); + ctx->trigger_cb = action_gpmi_rehash; + + hid_register_action(ctx); +} + +#ifndef PLUGIN_INIT_NAME +#define PLUGIN_INIT_NAME pcb_plugin_init +#endif + +void PLUGIN_INIT_NAME (); + +static void load_base_and_cfg(void) +{ + char *dir, *libdirg, *libdirh, *wdir, *wdirh, *hdirh, *home; + void **gpmi_asm_scriptname; + gpmi_package *scripts = NULL; + + libdirg = resolve_path_inplace(Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins", NULL)); + libdirh = resolve_path_inplace(Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); + wdirh = resolve_path_inplace(Concat ("plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); + wdir = Concat("plugins", NULL); + + home = getenv ("PCB_RND_GPMI_HOME"); + if (home == NULL) + home = homedir; + + hdirh = resolve_path_inplace(Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, HOST, NULL)); + + fprintf(stderr, "gpmi dirs: lg=%s lh=%s wh=%s w=%s hh=%s\n", libdirg, libdirh, wdirh, wdir, hdirh); + + /* first add package search path to all host-specific plugin dirs + This is needed because a script installed in ~/.pcb/plugins/*.conf + (added automatically from, the gui) + could depend on a package being anywhere else + */ + gpmi_path_insert(GPMI_PATH_PACKAGES, libdirh); + gpmi_path_insert(GPMI_PATH_PACKAGES, libdirg); + gpmi_path_insert(GPMI_PATH_PACKAGES, wdirh); + gpmi_path_insert(GPMI_PATH_PACKAGES, hdirh); + + /* the final fallback - append this as loading anything from here is arch-unsafe */ + gpmi_path_append(GPMI_PATH_PACKAGES, wdir); + + + gpmi_err_stack_enable(); + if (gpmi_pkg_load("gpmi_scripts", 0, NULL, NULL, &scripts)) + { + gpmi_err_stack_process_str(gpmi_hid_print_error); + abort(); + } + gpmi_err_stack_destroy(NULL); + + + gpmi_asm_scriptname = gpmi_pkg_resolve(scripts, "gpmi_scripts_asm_scriptname"); + assert(gpmi_asm_scriptname != NULL); + *gpmi_asm_scriptname = gpmi_hid_asm_scriptname; + + register_actions(); + event_bind(EVENT_GUI_INIT, ev_gui_init, NULL, PLUGIN_INIT_NAME); + + hid_gpmi_load_dir(libdirh, 0); + hid_gpmi_load_dir(libdirg, 0); + + dir = Concat(PCBLIBDIR, PCB_DIR_SEPARATOR_S "plugins", NULL); + hid_gpmi_load_dir(dir, 1); + free(dir); + + if (home != NULL) { + hid_gpmi_load_dir (hdirh, 0); + + dir = resolve_path_inplace(Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins", NULL)); + hid_gpmi_load_dir(dir, 1); + free(dir); + } + + hid_gpmi_load_dir(wdirh, 0); + hid_gpmi_load_dir(wdir, 0); + + free(wdir); + free(wdirh); + free(libdirh); + free(hdirh); +} + + +void PLUGIN_INIT_NAME () +{ + + printf("pcb-gpmi hid is loaded.\n"); + gpmi_init(); + load_base_and_cfg(); +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/gpmi_plugin.h (revision 1068) @@ -0,0 +1,3 @@ +extern int gpmi_hid_gui_inited; /* whether the gui is already initialzied */ +void gpmi_hid_print_error(gpmi_err_stack_t *entry, char *string); + Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.c (revision 1068) @@ -0,0 +1,241 @@ +#include +#include +#include +#include +#include +#include "src/misc.h" +#include "src/event.h" +#include "gpmi_plugin.h" +#include "scripts.h" + +extern HID *gui; + +#define attr_make_label(attr, name_, help_) \ +do { \ + memset((attr), 0, sizeof(HID_Attribute)); \ + (attr)->name = name_; \ + (attr)->help_text = help_; \ + (attr)->type = HID_Label; \ +} while(0) + +#define attr_make_label_str(attr, name1, name2, help_) \ +do { \ + char *__names__; \ + __names__ = Concat(name1, name2, NULL); \ + attr_make_label(attr, __names__, help_); \ +} while(0) + + +#define attr_make_enum(attr, name_, help_, enum_vals, default_item) \ +do { \ + memset((attr), 0, sizeof(HID_Attribute)); \ + (attr)->name = name_; \ + (attr)->help_text = help_; \ + (attr)->type = HID_Enum; \ + (attr)->enumerations = enum_vals; \ + (attr)->default_val.int_value = default_item; \ +} while(0) + +static hid_gpmi_script_info_t *choose_script(const char **operations, int *operation) +{ + HID_Attribute attr[3]; + HID_Attr_Val result[3]; + char **scrl, **s; + hid_gpmi_script_info_t *i; + int n, res; + + n = gpmi_hid_scripts_count(); + + scrl = malloc(sizeof(char *) * (n+1)); + for(i = hid_gpmi_script_info, n = 0; i != NULL; i = i->next, n++) { + char *basename; + + basename = strrchr(i->name, PCB_DIR_SEPARATOR_C); + if (basename == NULL) + basename = i->name; + else + basename++; + + scrl[n] = Concat(basename, "\t", i->module_name, NULL); + } + scrl[n] = NULL; + + attr_make_enum(&attr[0], "script", "Select an item from the list of scripts loaded", (const char **)scrl, -1); + + if (operations != NULL) + attr_make_enum(&attr[1], "operation", "Choose what to do with the script", operations, *operation); + + res = gui->attribute_dialog(attr, 1 + (operations != NULL), result, "GPMI manage scripts - select script", "Select one of the scripts already loaded"); + + /* free scrl slots before return */ + for(s = scrl; *s != NULL; s++) + free(*s); + + if (res) { + if (operation != NULL) + *operation = -1; + return NULL; + } + + if ((operations != NULL) && (operation != NULL)) + *operation = result[1].int_value; + +/* printf("res=%d\n", result[0].int_value);*/ + + if (result[0].int_value != -1) { + for(i = hid_gpmi_script_info, n = result[0].int_value; i != NULL && n != 0; i = i->next, n--); +/* printf("name=%s\n", i->name);*/ + return i; + } + return NULL; +} + +static hid_gpmi_script_info_t *load_script(void) +{ + char *fn, *ext; + hid_gpmi_script_info_t *info; + int default_mod = -1; + HID_Attribute attr[3]; + HID_Attr_Val result[3]; + char *exts[] = { + ".tcl", "tcl", + ".lua", "lua", + ".awk", "mawk", + ".mawk", "mawk", + ".py", "python", + ".scm", "scheme", + ".rb", "mruby", + ".ruby", "mruby", + ".st", "stutter", + ".pas", "ghli", + ".pl", "perl", + ".php", "php", + ".sh", "cli", + ".bash", "cli", + NULL, NULL + }; + const char *modules[] = { "tcl", "lua", "mawk", "python","scheme", "mruby", + "stutter", "ghli", "perl", "php", "cli", NULL }; + + + fn = gui->fileselect("Load script", "Load a GPMI script", NULL, NULL, "gpmi_load_script", HID_FILESELECT_READ); + + if (fn == NULL) + return NULL; + + ext = strrchr(fn, '.'); + if (ext != NULL) { + char **s; + const char **i; + /* find the extension in the extension->module pairs */ + for(s = exts; s[0] != NULL; s+=2) + if (strcmp(ext, s[0]) == 0) + break; + + /* if found, look up the "default enum value" for that module */ + if (s[1] != NULL) { + int n; + for(i = modules, n = 0; *i != NULL; i++,n++) { + if (strcmp(*i, s[1]) == 0) { + default_mod = n; + break; + } + } + } + } + + attr_make_enum(&attr[0], "module", "Select a GPMI module to interpret the script", modules, default_mod); + + if (gui->attribute_dialog(attr, 1, result, "GPMI manage scripts - select module", "Select one of GPMI modules to interpret the script")) + return NULL; + + if (result[0].int_value < 0) + return NULL; + + info = hid_gpmi_load_module(NULL, modules[result[0].int_value], fn, NULL); + if (info == NULL) + gui->report_dialog("GPMI script load", "Error loading the script.\nPlease consult the message log for details."); + return info; +} + +static void script_details(hid_gpmi_script_info_t *i) +{ + HID_Attribute attr[4]; + HID_Attr_Val result[4]; + char *cf; + + cf = i->conffile_name == NULL ? "" : i->conffile_name; + + + attr_make_label_str(&attr[0], "File name: ", i->name, "File name of the script (if not absolute, it's relative to the config file)"); + attr_make_label_str(&attr[1], "GPMI module: ", i->module_name, "Name of the GPMI module that is interpreting the script"); + attr_make_label_str(&attr[2], "Config file: ", cf, "Name of config file that requested the script to be loaded "); + gui->attribute_dialog(attr, 3, result, "GPMI manage scripts - script details", "Displaying detailed info on a script already loaded"); + free(attr[0].name); + free(attr[1].name); + free(attr[2].name); +} + +void gpmi_hid_manage_scripts(void) +{ + hid_gpmi_script_info_t *i; + static const char *err_no_script = "Error: you didn't select a script"; +#define CONSULT "Please consult the message log for details." + + const char *operations[] = {"show details...", "reload", "unload", "unload and remove from the config file", "load a new script...", "load a new script and add it in the config...", NULL}; + int op = 0; + i = choose_script(operations, &op); + switch(op) { + case 0: + if (i != NULL) + script_details(i); + else + gui->report_dialog("GPMI script details", err_no_script); + break; + case 1: + if (i != NULL) { + i = hid_gpmi_reload_module(i); + if (i == NULL) + gui->report_dialog("GPMI script reload", "Error reloading the script.\nThe script is now unloaded.\n" CONSULT "\n(e.g. there may be syntax errors in the script source)."); + } + else + gui->report_dialog("GPMI script reload", err_no_script); + break; + case 2: + if (i != NULL) { + if (gpmi_hid_script_unload(i) != 0) + gui->report_dialog("GPMI script unload", "Error unloading the script.\n" CONSULT "\n"); + } + else + gui->report_dialog("GPMI script unload", err_no_script); + break; + case 3: + if (i != NULL) { + int r1, r2; + r1 = gpmi_hid_script_remove(i); + r2 = gpmi_hid_script_unload(i); + if (r1 || r2) { + char *msg; + msg = Concat("Error:", + (r1 ? "couldnt't remove the script from the config file;" : ""), + (r2 ? "couldnt't unload the script;" : ""), + "\n" CONSULT "\n", NULL); + gui->report_dialog("GPMI script unload and remove", msg); + free(msg); + } + else + gui->report_dialog("GPMI script unload and remove", err_no_script); + } + break; + case 4: + load_script(); + break; + case 5: + i = load_script(); + if (i != NULL) { + if (gpmi_hid_script_addcfg(i) != 0) + gui->report_dialog("GPMI script add to config", "Error adding the script in user configuration.\n" CONSULT "\n"); + } + break; + } +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/manage_scripts.h (revision 1068) @@ -0,0 +1 @@ +void gpmi_hid_manage_scripts(void); Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.c =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.c (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.c (revision 1068) @@ -0,0 +1,366 @@ +#include +#include +#include +#include +#include +#include +#include +#include "src/misc.h" +#include "src/event.h" +#include "src/error.h" +#include "gpmi_plugin.h" +#include "scripts.h" + +#define CONFNAME "pcb-rnd-gpmi.conf" + +hid_gpmi_script_info_t *hid_gpmi_script_info = NULL; + +int gpmi_hid_scripts_count() +{ + int n; + hid_gpmi_script_info_t *i; + + for(i = hid_gpmi_script_info, n = 0; i != NULL; i = i->next, n++) ; + + return n; +} + +static void hid_gpmi_script_info_free(hid_gpmi_script_info_t *i) +{ + int ev; + char *ev_args; + ev = gpmi_event_find("ACTE_unload", &ev_args); + if (ev >= 0) + gpmi_event(i->module, ev, i->conffile_name); + + gpmi_mod_unload(i->module); + free(i->name); + free(i->module_name); + free(i->conffile_name); +} + +static hid_gpmi_script_info_t *hid_gpmi_script_info_add(hid_gpmi_script_info_t *i, gpmi_module *module, const char *name_, const char *module_name_, const char *conffile_name_) +{ + char *name, *module_name, *conffile_name; + /* make these copies before the free()'s because of reload calling us with + the same pointers... */ + name = strdup(name_); + module_name = strdup(module_name_); + if (conffile_name_ != NULL) + conffile_name = strdup(conffile_name_); + else + conffile_name = NULL; + + if (i == NULL) { + i = malloc(sizeof(hid_gpmi_script_info_t)); + i->next = hid_gpmi_script_info; + hid_gpmi_script_info = i; + } + else + hid_gpmi_script_info_free(i); + + i->module = module; + i->name = name; + i->module_name = module_name; + i->conffile_name = conffile_name; + return i; +} + +hid_gpmi_script_info_t *hid_gpmi_lookup(const char *name) +{ + hid_gpmi_script_info_t *i; + if (name == NULL) + return NULL; + for(i = hid_gpmi_script_info; i != NULL; i = i->next) + if (strcmp(name, i->name) == 0) + return i; + return NULL; +} + +/* Unload a script and remove it from the list */ +static void hid_gpmi_script_info_del(hid_gpmi_script_info_t *inf) +{ + hid_gpmi_script_info_t *i, *prev; + prev = NULL; + for(i = hid_gpmi_script_info; i != NULL; prev = i, i = i->next) { + if (i == inf) { + /* unlink */ + if (prev == NULL) + hid_gpmi_script_info = inf->next; + else + prev->next = inf->next; + hid_gpmi_script_info_free(inf); + free(inf); + return; + } + } +} + +static const char *conf_dir = NULL; + +hid_gpmi_script_info_t *hid_gpmi_load_module(hid_gpmi_script_info_t *i, const char *module_name, const char *params, const char *config_file_name) +{ + gpmi_module *module; + + Message("Loading GPMI module %s with params %s...\n", module_name, params); + module = gpmi_mod_load(module_name, params); + if (module == NULL) { + Message(" Failed loading the script. Details:\n"); + gpmi_err_stack_process_str(gpmi_hid_print_error); + } + gpmi_err_stack_destroy(NULL); + + if (module != NULL) { + hid_gpmi_script_info_t *ri; + int ev; + + ri = hid_gpmi_script_info_add(i, module, params, module_name, config_file_name); + if ((ri != NULL) && (gpmi_hid_gui_inited)) { + char *ev_args; + /* If a script is loaded with a GUI already inited, send the event right after the load */ + ev = gpmi_event_find("ACTE_gui_init", &ev_args); + gpmi_event(ri->module, ev, 0, NULL); + } + return ri; + } + + return NULL; +} + +hid_gpmi_script_info_t *hid_gpmi_reload_module(hid_gpmi_script_info_t *i) +{ + hid_gpmi_script_info_t *r; + const char *old_cd; + + old_cd = conf_dir; + + if (i->conffile_name != NULL) { + char *end; + conf_dir = strdup(i->conffile_name); + end = strrchr(conf_dir, PCB_DIR_SEPARATOR_C); + if (end == NULL) { + free((char *)conf_dir); + conf_dir = NULL; + } + else + *end = '\0'; + } + else + conf_dir = NULL; + + r = hid_gpmi_load_module(i, i->module_name, i->name, i->conffile_name); + + if (conf_dir != NULL) + free((char *)conf_dir); + conf_dir = old_cd; + + return r; +} + +/* Read and parse gpmi config file fin; + if fout is NULL, take cfn as config name and load all modules, return number of modules loaded; + else write all lines to fout, but comment out the one whose second token matches cfn, return number of commented lines + +*/ + +static int cfgfile(FILE *fin, FILE *fout, char *cfn) +{ +char line[1024], *module, *params, *s; + int found = 0; + + while(!(feof(fin))) { + *line = '\0'; + fgets(line, sizeof(line), fin); + switch(*line) { + case '\0': + case '\n': + case '\r': + case '#': + /* Empty line or comment */ + if (fout != NULL) + fprintf(fout, "%s", line); + break; + default: + module = strdup(line); + params = module + strcspn(module, "\t "); + while((*params == ' ') || (*params == '\t')) { + *(params) = '\0'; + params++; + } + s = strchr(params, '\n'); + *s = '\0'; + if (fout == NULL) { + fprintf(stderr, " ...loading %s %s\n", module, params); + hid_gpmi_load_module(NULL, module, params, cfn); + found++; + } + else { + if (strcmp(params, cfn) == 0) { + fprintf(fout, "# removed from pcb-rnd GUI: "); + found++; + } + if (fout != NULL) + fprintf(fout, "%s", line); + } + free(module); + } + } + + return found; +} + +void hid_gpmi_load_dir(const char *dir, int add_pkg_path) +{ + FILE *f; + char *cfn; + + conf_dir = dir; + cfn = Concat(dir, PCB_DIR_SEPARATOR_S, CONFNAME, NULL); +#ifdef CONFIG_DEBUG + fprintf(stderr, "pcb-gpmi: opening config: %s\n", cfn); +#endif + f = fopen(cfn, "r"); + if (f == NULL) { + free(cfn); +#ifdef CONFIG_DEBUG + fprintf(stderr, " ...failed\n"); +#endif + return; + } + + if (add_pkg_path) + gpmi_path_insert(GPMI_PATH_PACKAGES, dir); + + cfgfile(f, NULL, cfn); + + fclose(f); + free(cfn); + conf_dir = NULL; +} + +/* Dummy script name generator allows loading from any path */ +char *gpmi_hid_asm_scriptname(const void *info, const char *file_name) +{ + char buffer[1024]; + const char *cd; + + switch(*file_name) { + case '~': + file_name += 2; + if (homedir != NULL) { + snprintf(buffer, sizeof(buffer), "%s%c%s", homedir, PCB_DIR_SEPARATOR_C, file_name); + fprintf(stderr, "asm_scriptname FN=%s\n", buffer); + return strdup(buffer); + } + else { + fprintf(stderr, "pcb-gpmi error: can't access $HOME for substituting ~\n"); +#ifdef CONFIG_DEBUG + printf("FN=%s\n", file_name); +#endif + return strdup(file_name); + } + case PCB_DIR_SEPARATOR_C: /* full path */ + return strdup(file_name); + default: /* relative path - must be relative to the current conf_dir */ + if ((file_name[0] == '.') && (file_name[1] == PCB_DIR_SEPARATOR_C)) + file_name += 2; + if (conf_dir == NULL) + cd = "."; + else + cd = conf_dir; + snprintf(buffer, sizeof(buffer), "%s%c%s", cd, PCB_DIR_SEPARATOR_C, file_name); +#ifdef CONFIG_DEBUG + printf("FN=%s\n", buffer); +#endif + return strdup(buffer); + } + return NULL; +} + +int gpmi_hid_script_unload(hid_gpmi_script_info_t *i) +{ + hid_gpmi_script_info_del(i); + return 0; +} + +int gpmi_hid_script_remove(hid_gpmi_script_info_t *i) +{ + FILE *fin, *fout; + char *tmpfn; + int res; + + if (i->conffile_name == NULL) { + Message("gpmi_hid_script_remove(): can't remove script from configs, the script is not loaded from a config.\n"); + return -1; + } + + fin = fopen(i->conffile_name, "r"); + if (fin == NULL) { + Message("gpmi_hid_script_remove(): can't remove script from configs, can't open %s for read.\n", i->conffile_name); + return -1; + } + tmpfn = Concat(i->conffile_name, ".tmp", NULL); + fout = fopen(tmpfn, "w"); + if (fout == NULL) { + Message("gpmi_hid_script_remove(): can't remove script from configs, can't create %s.\n", tmpfn); + fclose(fin); + free(tmpfn); + return -1; + } + + res = cfgfile(fin, fout, i->name); + + fclose(fin); + fclose(fout); + + if (res < 1) { + Message("gpmi_hid_script_remove(): can't remove script from configs, can't find the correspondign config line in %s\n", i->conffile_name); + free(tmpfn); + return -1; + } + + if (rename(tmpfn, i->conffile_name) != 0) { + Message("gpmi_hid_script_remove(): can't remove script from configs, can't move %s to %s.\n", tmpfn, i->conffile_name); + free(tmpfn); + return -1; + } + + free(tmpfn); + return 0; +} + +int gpmi_hid_script_addcfg(hid_gpmi_script_info_t *i) +{ + char *fn, *home; + FILE *f; + + home = getenv ("PCB_RND_GPMI_HOME"); + if (home == NULL) + home = homedir; + + if (homedir != NULL) { + fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb", NULL); + mkdir(fn, 0755); + free(fn); + + fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins", NULL); + mkdir(fn, 0755); + free(fn); + + fn = Concat(home, PCB_DIR_SEPARATOR_S ".pcb" PCB_DIR_SEPARATOR_S "plugins" PCB_DIR_SEPARATOR_S, CONFNAME, NULL); + } + else + fn = Concat("plugins" PCB_DIR_SEPARATOR_S, CONFNAME, NULL); + + f = fopen(fn, "a"); + if (f == NULL) { + Message("gpmi_hid_script_addcfg: can't open %s for write\n", fn); + return -1; + } + + fprintf(f, "\n%s\t%s\n", i->module_name, i->name); + fclose(f); + + free(fn); + return 0; +} Index: src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.h =================================================================== --- src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.h (nonexistent) +++ src_plugins/gpmi/pcb-gpmi/gpmi_plugin/scripts.h (revision 1068) @@ -0,0 +1,39 @@ +typedef struct hid_gpmi_script_info_s hid_gpmi_script_info_t; + +struct hid_gpmi_script_info_s { + char *name; + char *module_name; + char *conffile_name; + gpmi_module *module; + + hid_gpmi_script_info_t *next; +}; + +extern hid_gpmi_script_info_t *hid_gpmi_script_info; + +/* Load a GPMI module; if i is NULL, allocate a new slot on the list, else unload + i first and place the new module in place of i. */ +hid_gpmi_script_info_t *hid_gpmi_load_module(hid_gpmi_script_info_t *i, const char *module_name, const char *params, const char *config_file_name); + +/* Reload a script - useful if the source of the script has changed + Reloads a module already loaded; return NULL on error. */ +hid_gpmi_script_info_t *hid_gpmi_reload_module(hid_gpmi_script_info_t *i); + +/* look up a module by name - slow linear search */ +hid_gpmi_script_info_t *hid_gpmi_lookup(const char *name); + +void hid_gpmi_load_dir(const char *dir, int add_pkg_path); +char *gpmi_hid_asm_scriptname(const void *info, const char *file_name); + +/* Return the number of scripts (gpmi modules) loaded */ +int gpmi_hid_scripts_count(); + +/* Unload a script (also removes i from the list) - temporary effect, + the script will be loaded again on the next startup */ +int gpmi_hid_script_unload(hid_gpmi_script_info_t *i); + +/* Remove a script from the config file (but do not unload it now) */ +int gpmi_hid_script_remove(hid_gpmi_script_info_t *i); + +/* Edit a config file so that the script is in it */ +int gpmi_hid_script_addcfg(hid_gpmi_script_info_t *i);