Index: trunk/scconfig/Rev.h =================================================================== --- trunk/scconfig/Rev.h (revision 24823) +++ trunk/scconfig/Rev.h (revision 24824) @@ -1 +1 @@ -static const int myrev = 24816; +static const int myrev = 24824; Index: trunk/scconfig/Rev.tab =================================================================== --- trunk/scconfig/Rev.tab (revision 24823) +++ trunk/scconfig/Rev.tab (revision 24824) @@ -1,3 +1,4 @@ +24824 configure move window placement from dialogs to lib_hid_commonfor hidlib cleanup 24816 configure safety wrapper around unlink, opendir, closedir and readdir 24736 configure make distclean fixes to really remove all generated files 24625 configure io_kicad common layer table code among read and write side Index: trunk/scconfig/plugins.h =================================================================== --- trunk/scconfig/plugins.h (revision 24823) +++ trunk/scconfig/plugins.h (revision 24824) @@ -9,7 +9,7 @@ plugin_def("lib_gensexpr", "#s-expression library", sdisable, 0) plugin_def("lib_gtk_common", "all-hid_gtk common code", sdisable, 0) plugin_def("lib_gtk_hid", "hid_gtk generic part", sdisable, 0) -plugin_def("lib_hid_common", "all-hid common code", sdisable, 0) +plugin_def("lib_hid_common", "all-gui-hid common code", sdisable, 0) plugin_def("lib_hid_gl", "openGL rendering", sdisable, 0) plugin_def("lib_legacy_func", "legacy functions", sbuildin, 1) plugin_def("lib_netmap", "map nets and objects", sdisable, 0) @@ -149,7 +149,6 @@ plugin_dep("hid_gtk2_gl", "lib_hid_gl", 0) plugin_dep("hid_gtk3_cairo", "lib_gtk_common", 0) plugin_dep("hid_gtk3_cairo", "lib_gtk_hid", 0) -plugin_dep("hid_lesstif", "dialogs", 0) plugin_dep("hid_lesstif", "lib_hid_common", 0) plugin_dep("import_dsn", "lib_compat_help", 0) plugin_dep("import_ipcd356", "lib_compat_help", 0) @@ -166,8 +165,7 @@ plugin_dep("io_pcb", "lib_compat_help", 0) plugin_dep("io_tedax", "lib_compat_help", 0) plugin_dep("io_tedax", "lib_netmap", 0) -plugin_dep("lib_gtk_common", "dialogs", 0) -plugin_dep("lib_gtk_hid", "dialogs", 0) +plugin_dep("lib_gtk_common", "lib_hid_common", 0) plugin_dep("lib_gtk_hid", "lib_hid_common", 0) plugin_dep("lib_vfs", "propedit", 0) plugin_dep("millpath", "lib_polyhelp", 0) Index: trunk/src/Makefile.dep =================================================================== --- trunk/src/Makefile.dep (revision 24823) +++ trunk/src/Makefile.dep (revision 24824) @@ -417,7 +417,7 @@ ../src_3rd/puplug/puplug.h ../src_3rd/puplug/libs.h \ ../src_3rd/puplug/os_dep.h ../src_3rd/puplug/config.h \ ../src_3rd/puplug/libs.h ../src_3rd/puplug/error.h funchash_core.h \ - funchash.h funchash_core_list.h ../src_plugins/dialogs/dialogs_conf.h \ + funchash.h funchash_core_list.h ../src_plugins/lib_hid_common/dialogs_conf.h \ conf.h ../src_3rd/liblihata/lihata.h ../src_3rd/genvector/vtp0.h \ list_conf.h conf.h ../src_plugins/dialogs/dlg_test.c board.h \ vtroutestyle.h layer_grp.h rats_patch.h board.h obj_text.h \ @@ -442,7 +442,7 @@ ../src_plugins/dialogs/dlg_netlist.c \ ../src_plugins/dialogs/dlg_plugins.c \ ../src_plugins/dialogs/dlg_printcalib.c hid_init.h \ - ../src_plugins/dialogs/place.c safe_fs.h ../src_3rd/genht/ht.c \ + safe_fs.h ../src_3rd/genht/ht.c \ ../src_3rd/genht/ht_inlines.h ../src_plugins/dialogs/dlg_view.h \ ../src_plugins/dialogs/dlg_pref.h conf_hid.h \ ../src_plugins/dialogs/dlg_pref_sizes.h \ @@ -452,7 +452,7 @@ ../src_plugins/dialogs/dlg_pref_color.h \ ../src_plugins/dialogs/dlg_pref_win.h \ ../src_plugins/dialogs/dlg_pref_conf.h ../src_plugins/dialogs/act_dad.h \ - dolists.h ../src_plugins/dialogs/dialogs_conf_fields.h + dolists.h ../src_plugins/lib_hid_common/dialogs_conf_fields.h ../src_plugins/dialogs/dlg_about.o: ../src_plugins/dialogs/dlg_about.c \ ../config.h ../src_3rd/genvector/gds_char.h \ ../src_3rd/genvector/genvector_impl.h \ @@ -710,7 +710,7 @@ paths.h ../src_plugins/dialogs/dlg_pref_layer.c stub_draw.h draw.h \ ../src_plugins/dialogs/dlg_pref_color.c \ ../src_plugins/dialogs/dlg_pref_win.c \ - ../src_plugins/dialogs/dialogs_conf.h \ + ../src_plugins/lib_hid_common/dialogs_conf.h \ ../src_plugins/dialogs/dlg_pref_conf.c misc_util.h \ ../src_plugins/dialogs/dlg_pref_confedit.c ../src_plugins/dialogs/dlg_view.o: ../src_plugins/dialogs/dlg_view.c \ @@ -4277,7 +4277,7 @@ ../src_3rd/puplug/puplug.h ../src_3rd/puplug/libs.h \ ../src_3rd/puplug/os_dep.h ../src_3rd/puplug/config.h \ ../src_3rd/puplug/libs.h ../src_3rd/puplug/error.h \ - ../src_plugins/dialogs/place.h \ + ../src_plugins/lib_hid_common/place.h \ ../src_plugins/lib_gtk_common/hid_gtk_conf_fields.h ../src_plugins/lib_gtk_common/ui_crosshair.o: \ ../src_plugins/lib_gtk_common/ui_crosshair.c ../config.h \ @@ -4766,7 +4766,7 @@ ../src_3rd/genlist/gendlist.h \ ../src_plugins/lib_hid_common/cli_history.h \ ../src_plugins/lib_hid_common/lib_hid_common.h \ - ../src_plugins/lib_hid_common/lib_hid_common_conf.h conf.h \ + conf.h \ global_typedefs.h pcb_bool.h unit.h pcb-printf.h \ ../src_3rd/genvector/gds_char.h ../src_3rd/genvector/genvector_impl.h \ ../src_3rd/genvector/genvector_undef.h ../src_3rd/liblihata/lihata.h \ @@ -4860,9 +4860,7 @@ ../src_3rd/genht/ht.h ../src_3rd/genht/hash.h obj_pstk_list.h obj_pstk.h \ vtpadstack.h obj_pstk_shape.h polygon.h vtpadstack_t.h data_it.h data.h \ flag.h ../src_plugins/lib_hid_common/lead_user.h \ - ../src_plugins/lib_hid_common/lib_hid_common.h \ - ../src_plugins/lib_hid_common/lib_hid_common_conf.h \ - ../src_plugins/lib_hid_common/lib_hid_common_conf_fields.h + ../src_plugins/lib_hid_common/lib_hid_common.h ../src_plugins/lib_hid_common/routest_menu.o: \ ../src_plugins/lib_hid_common/routest_menu.c ../config.h board.h \ ../src_3rd/genht/htsp.h ../src_3rd/genht/ht.h global_typedefs.h \ Index: trunk/src_plugins/dialogs/place.c =================================================================== --- trunk/src_plugins/dialogs/place.c (revision 24823) +++ trunk/src_plugins/dialogs/place.c (nonexistent) @@ -1,307 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2018 Tibor 'Igor2' Palinkas - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/pcb-rnd - * lead developer: http://repo.hu/projects/pcb-rnd/contact.html - * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") - */ - -#include "config.h" -#include "safe_fs.h" - -static const char *place_cookie = "dialogs/place"; - -typedef struct { - int x, y, w, h; -} wingeo_t; - -wingeo_t wingeo_invalid = {0, 0, 0, 0}; - -typedef const char *htsw_key_t; -typedef wingeo_t htsw_value_t; -#define HT(x) htsw_ ## x -#define HT_INVALID_VALUE wingeo_invalid; -#include -#include -#undef HT -#include - -static htsw_t wingeo; - -static void pcb_dialog_store(const char *id, int x, int y, int w, int h) -{ - htsw_entry_t *e; - wingeo_t wg; - -/* pcb_trace("dialog place set: '%s' %d;%d %d*%d\n", id, x, y, w, h);*/ - - e = htsw_getentry(&wingeo, (char *)id); - if (e != NULL) { - e->value.x = x; - e->value.y = y; - e->value.w = w; - e->value.h = h; - return; - } - - wg.x = x; - wg.y = y; - wg.w = w; - wg.h = h; - htsw_set(&wingeo, pcb_strdup(id), wg); -} - - -static void pcb_dialog_place(void *user_data, int argc, pcb_event_arg_t argv[]) -{ - const char *id; - int *geo; - htsw_entry_t *e; - - if ((argc < 3) || (argv[1].type != PCB_EVARG_PTR) || (argv[2].type != PCB_EVARG_STR)) - return; - - id = argv[2].d.s; - geo = argv[3].d.p; - - e = htsw_getentry(&wingeo, (char *)id); - if (e != NULL) { - geo[0] = e->value.x; - geo[1] = e->value.y; - geo[2] = e->value.w; - geo[3] = e->value.h; - } -/* pcb_trace("dialog place: %p '%s'\n", hid_ctx, id);*/ -} - -static void pcb_dialog_resize(void *user_data, int argc, pcb_event_arg_t argv[]) -{ - if ((argc < 7) || (argv[1].type != PCB_EVARG_PTR) || (argv[2].type != PCB_EVARG_STR)) - return; - -/* hid_ctx = argv[1].d.p;*/ - pcb_dialog_store(argv[2].d.s, argv[3].d.i, argv[4].d.i, argv[5].d.i, argv[6].d.i); -} - -static vtp0_t cleanup_later; -static char *str_cleanup_later(const char *path) -{ - char *s = pcb_strdup(path); - vtp0_append(&cleanup_later, s); - return s; -} - -static void place_conf_set(conf_role_t role, const char *path, int val) -{ - static int dummy; - - if (conf_get_field(path) == NULL) - conf_reg_field_(&dummy, 1, CFN_INTEGER, str_cleanup_later(path), "", 0); - conf_setf(role, path, -1, "%d", val); -} - -static void place_conf_load(conf_role_t role, const char *path, int *val) -{ - conf_native_t *nat = conf_get_field(path); - conf_role_t crole; - static int dummy; - - if (conf_get_field(path) == NULL) { - conf_reg_field_(&dummy, 1, CFN_INTEGER, str_cleanup_later(path), "", 0); - conf_update(path, -1); - } - - nat = conf_get_field(path); - if ((nat == NULL) || (nat->prop->src == NULL) || (nat->prop->src->type != LHT_TEXT)) { - pcb_message(PCB_MSG_ERROR, "Can not load window geometry from invalid node for %s\n", path); - return; - } - - /* there are priorities which is hanled by conf merging. To make sure - only the final value is loaded, check if the final native's source - role matches the role that's being loaded. Else the currently loading - role is lower prio and didn't contribute to the final values and should - be ignored. */ - crole = conf_lookup_role(nat->prop->src); - if (crole != role) - return; - - /* need to atoi() directly from the lihata node because the native value - is dummy and shared among all nodes - cheaper to atoi than to do - a proper allocation for the native value. */ - *val = atoi(nat->prop->src->data.text.value); -} - -#define BASEPATH "plugins/dialogs/window_geometry/" -void pcb_wplc_load(conf_role_t role) -{ - char *end, *end2, path[128 + sizeof(BASEPATH)]; - lht_node_t *nd, *root; - lht_dom_iterator_t it; - int x, y, w, h; - - strcpy(path, BASEPATH); - end = path + strlen(BASEPATH); - - root = conf_lht_get_at(role, path, 0); - if (root == NULL) - return; - - for(nd = lht_dom_first(&it, root); nd != NULL; nd = lht_dom_next(&it)) { - int len; - if (nd->type != LHT_HASH) - continue; - len = strlen(nd->name); - if (len > 64) - continue; - memcpy(end, nd->name, len); - end[len] = '/'; - end2 = end + len+1; - - x = y = -1; - w = h = 0; - strcpy(end2, "x"); place_conf_load(role, path, &x); - strcpy(end2, "y"); place_conf_load(role, path, &y); - strcpy(end2, "width"); place_conf_load(role, path, &w); - strcpy(end2, "height"); place_conf_load(role, path, &h); - pcb_dialog_store(nd->name, x, y, w, h); - } -} - - -static void place_maybe_save(conf_role_t role, int force) -{ - htsw_entry_t *e; - char path[128 + sizeof(BASEPATH)]; - char *end, *end2; - - switch(role) { - case CFR_USER: if (!force && !conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_user) return; break; - case CFR_DESIGN: if (!force && !conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_design) return; break; - case CFR_PROJECT: if (!force && !conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_project) return; break; - default: return; - } - - strcpy(path, BASEPATH); - end = path + strlen(BASEPATH); - for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) { - int len = strlen(e->key); - if (len > 64) - continue; - memcpy(end, e->key, len); - end[len] = '/'; - end2 = end + len+1; - - strcpy(end2, "x"); place_conf_set(role, path, e->value.x); - strcpy(end2, "y"); place_conf_set(role, path, e->value.y); - strcpy(end2, "width"); place_conf_set(role, path, e->value.w); - strcpy(end2, "height"); place_conf_set(role, path, e->value.h); - } - - - if (role != CFR_DESIGN) { - int r = conf_save_file(NULL, (PCB == NULL ? NULL : PCB->Filename), role, NULL); - if (r != 0) - pcb_message(PCB_MSG_ERROR, "Failed to save window geometry in %s\n", conf_role_name(role)); - } -} - -/* event handlers that run before the current pcb is saved to save win geo - in the board conf and after loading a new board to fetch window placement - info. */ -static void place_save_pre(void *user_data, int argc, pcb_event_arg_t argv[]) -{ - place_maybe_save(CFR_PROJECT, 0); - place_maybe_save(CFR_DESIGN, 0); -} - -static void place_load_post(void *user_data, int argc, pcb_event_arg_t argv[]) -{ - pcb_wplc_load(CFR_PROJECT); - pcb_wplc_load(CFR_DESIGN); -} - -void pcb_wplc_save_to_role(conf_role_t role) -{ - place_maybe_save(role, 1); -} - -int pcb_wplc_save_to_file(const char *fn) -{ - htsw_entry_t *e; - FILE *f; - - f = pcb_fopen(fn, "w"); - if (f == NULL) - return -1; - - fprintf(f, "li:pcb-rnd-conf-v1 {\n"); - fprintf(f, " ha:overwrite {\n"); - fprintf(f, " ha:plugins {\n"); - fprintf(f, " ha:dialogs {\n"); - fprintf(f, " ha:window_geometry {\n"); - - - for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) { - fprintf(f, " ha:%s {\n", e->key); - fprintf(f, " x=%d\n", e->value.x); - fprintf(f, " y=%d\n", e->value.x); - fprintf(f, " width=%d\n", e->value.w); - fprintf(f, " height=%d\n", e->value.h); - fprintf(f, " }\n"); - } - - fprintf(f, " }\n"); - fprintf(f, " }\n"); - fprintf(f, " }\n"); - fprintf(f, " }\n"); - fprintf(f, "}\n"); - fclose(f); - return 0; -} - -static void pcb_dialog_place_uninit(void) -{ - htsw_entry_t *e; - int n; - - conf_unreg_fields(BASEPATH); - - place_maybe_save(CFR_USER, 0); - - for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) - free((char *)e->key); - htsw_uninit(&wingeo); - pcb_event_unbind_allcookie(place_cookie); - - for(n = 0; n < cleanup_later.used; n++) - free(cleanup_later.array[n]); - vtp0_uninit(&cleanup_later); -} - -static void pcb_dialog_place_init(void) -{ - htsw_init(&wingeo, strhash, strkeyeq); - pcb_event_bind(PCB_EVENT_SAVE_PRE, place_save_pre, NULL, place_cookie); - pcb_event_bind(PCB_EVENT_LOAD_POST, place_load_post, NULL, place_cookie); - pcb_wplc_load(CFR_SYSTEM); - pcb_wplc_load(CFR_USER); -} Index: trunk/src_plugins/dialogs/place.h =================================================================== --- trunk/src_plugins/dialogs/place.h (revision 24823) +++ trunk/src_plugins/dialogs/place.h (nonexistent) @@ -1,3 +0,0 @@ -#include "conf.h" -void pcb_wplc_load(conf_role_t role); - Index: trunk/src_plugins/dialogs/dialogs_conf.h =================================================================== --- trunk/src_plugins/dialogs/dialogs_conf.h (revision 24823) +++ trunk/src_plugins/dialogs/dialogs_conf.h (nonexistent) @@ -1,26 +0,0 @@ -#ifndef PCB_DIALOGS_CONF_H -#define PCB_DIALOGS_CONF_H - -#include "conf.h" - -typedef struct { - const struct plugins { - const struct dialogs { - const struct auto_save_window_geometry { - CFT_BOOLEAN to_design; - CFT_BOOLEAN to_project; - CFT_BOOLEAN to_user; - } auto_save_window_geometry; - const struct window_geometry { - const struct example_template { - CFT_INTEGER x; - CFT_INTEGER y; - CFT_INTEGER width; - CFT_INTEGER height; - } example_template; - } window_geometry; - } dialogs; - } plugins; -} conf_dialogs_t; - -#endif Index: trunk/src_plugins/dialogs/Plug.tmpasm =================================================================== --- trunk/src_plugins/dialogs/Plug.tmpasm (revision 24823) +++ trunk/src_plugins/dialogs/Plug.tmpasm (revision 24824) @@ -17,8 +17,6 @@ $(PLUGDIR)/dialogs/dlg_view.o $(PLUGDIR)/dialogs/xpm.o @] -put /local/pcb/mod/CONFFILE {dialogs.conf} -put /local/pcb/mod/CONF {$(PLUGDIR)/dialogs/dialogs_conf.h} switch /local/pcb/dialogs/controls case {buildin} include /local/pcb/tmpasm/buildin; end; Index: trunk/src_plugins/dialogs/dialogs.c =================================================================== --- trunk/src_plugins/dialogs/dialogs.c (revision 24823) +++ trunk/src_plugins/dialogs/dialogs.c (revision 24824) @@ -34,9 +34,10 @@ #include "hid_dad.h" #include "plugins.h" #include "funchash_core.h" -#include "dialogs_conf.h" +#include "../src_plugins/lib_hid_common/dialogs_conf.h" -const conf_dialogs_t conf_dialogs; +/* from lib_hid_common */ +extern const conf_dialogs_t dialogs_conf; /* include them all for static inlines */ #include "dlg_test.c" @@ -56,7 +57,6 @@ #include "dlg_netlist.c" #include "dlg_plugins.c" #include "dlg_printcalib.c" -#include "place.c" #include "dlg_view.h" #include "dlg_pref.h" @@ -105,7 +105,6 @@ void pplg_uninit_dialogs(void) { - pcb_event_unbind_allcookie(dialogs_cookie); pcb_dlg_netlist_uninit(); pcb_dlg_undo_uninit(); pcb_dlg_pstklib_uninit(); @@ -113,7 +112,6 @@ pcb_act_dad_uninit(); pcb_remove_actions_by_cookie(dialogs_cookie); pcb_view_dlg_uninit(); - pcb_dialog_place_uninit(); pcb_dlg_fontsel_uninit(); conf_unreg_fields("plugins/dialogs/"); pcb_dlg_log_uninit(); @@ -125,15 +123,8 @@ { PCB_API_CHK_VER; -#define conf_reg(field,isarray,type_name,cpath,cname,desc,flags) \ - conf_reg_field(conf_dialogs, field,isarray,type_name,cpath,cname,desc,flags); -#include "dialogs_conf_fields.h" - pcb_dlg_log_init(); - pcb_dialog_place_init(); PCB_REGISTER_ACTIONS(dialogs_action_list, dialogs_cookie) - pcb_event_bind(PCB_EVENT_DAD_NEW_DIALOG, pcb_dialog_place, NULL, dialogs_cookie); - pcb_event_bind(PCB_EVENT_DAD_NEW_GEO, pcb_dialog_resize, NULL, dialogs_cookie); pcb_act_dad_init(); pcb_dlg_pref_init(); pcb_dlg_pstklib_init(); Index: trunk/src_plugins/dialogs/dlg_pref_win.c =================================================================== --- trunk/src_plugins/dialogs/dlg_pref_win.c (revision 24823) +++ trunk/src_plugins/dialogs/dlg_pref_win.c (revision 24824) @@ -29,9 +29,9 @@ #include "dlg_pref.h" #include "conf.h" #include "conf_core.h" -#include "dialogs_conf.h" +#include "../src_plugins/lib_hid_common/dialogs_conf.h" -extern const conf_dialogs_t conf_dialogs; +extern const conf_dialogs_t dialogs_conf; extern void pcb_wplc_save_to_role(conf_role_t role); extern int pcb_wplc_save_to_file(const char *fn); @@ -38,9 +38,9 @@ static void pref_win_brd2dlg(pref_ctx_t *ctx) { PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wmaster, int_value, conf_core.editor.auto_place); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wboard, int_value, conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_design); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wproject, int_value, conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_project); - PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wuser, int_value, conf_dialogs.plugins.dialogs.auto_save_window_geometry.to_user); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wboard, int_value, dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_design); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wproject, int_value, dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_project); + PCB_DAD_SET_VALUE(ctx->dlg_hid_ctx, ctx->win.wuser, int_value, dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_user); } void pcb_dlg_pref_win_open(pref_ctx_t *ctx) Index: trunk/src_plugins/hid_lesstif/hid_lesstif.pup =================================================================== --- trunk/src_plugins/hid_lesstif/hid_lesstif.pup (revision 24823) +++ trunk/src_plugins/hid_lesstif/hid_lesstif.pup (revision 24824) @@ -5,5 +5,4 @@ $package hid-lesstif default buildin dep lib_hid_common -dep dialogs autoload 1 Index: trunk/src_plugins/lib_gtk_common/lib_gtk_common.pup =================================================================== --- trunk/src_plugins/lib_gtk_common/lib_gtk_common.pup (revision 24823) +++ trunk/src_plugins/lib_gtk_common/lib_gtk_common.pup (revision 24824) @@ -3,6 +3,6 @@ $long hid_gtk* common code (regardless of gtk version or drawing mechanism: for both gtk2 and gtk3 and for both sw rendering and gl) $state works $package lib-gtk -dep dialogs +dep lib_hid_common default disable-all Index: trunk/src_plugins/lib_gtk_common/lib_gtk_config.c =================================================================== --- trunk/src_plugins/lib_gtk_common/lib_gtk_config.c (revision 24823) +++ trunk/src_plugins/lib_gtk_common/lib_gtk_config.c (revision 24824) @@ -32,7 +32,7 @@ #include "lib_gtk_config.h" #include "hid_gtk_conf.h" #include "plugins.h" -#include "src_plugins/dialogs/place.h" +#include "src_plugins/lib_hid_common/place.h" static const char *lib_gtk_config_cookie = "lib_gtk_config"; Index: trunk/src_plugins/lib_gtk_hid/lib_gtk_hid.pup =================================================================== --- trunk/src_plugins/lib_gtk_hid/lib_gtk_hid.pup (revision 24823) +++ trunk/src_plugins/lib_gtk_hid/lib_gtk_hid.pup (revision 24824) @@ -5,4 +5,3 @@ $package lib-gtk default disable-all dep lib_hid_common -dep dialogs Index: trunk/src_plugins/lib_hid_common/lib_hid_common_conf.h =================================================================== --- trunk/src_plugins/lib_hid_common/lib_hid_common_conf.h (revision 24823) +++ trunk/src_plugins/lib_hid_common/lib_hid_common_conf.h (nonexistent) @@ -1,17 +0,0 @@ -#ifndef PCB_LIB_HID_COMMON_CONF_H -#define PCB_LIB_HID_COMMON_CONF_H - -#include "conf.h" - -typedef struct { - const struct plugins { - const struct lib_hid_common { - const struct cli_history { - CFT_STRING file; /* Path to the history file (empty/unset means history is not preserved) */ - CFT_INTEGER slots; /* Number of commands to store in the history */ - } cli_history; - } lib_hid_common; - } plugins; -} conf_lib_hid_common_t; - -#endif Index: trunk/src_plugins/lib_hid_common/Plug.tmpasm =================================================================== --- trunk/src_plugins/lib_hid_common/Plug.tmpasm (revision 24823) +++ trunk/src_plugins/lib_hid_common/Plug.tmpasm (revision 24824) @@ -6,10 +6,15 @@ $(PLUGDIR)/lib_hid_common/grid_menu.o $(PLUGDIR)/lib_hid_common/routest_menu.o $(PLUGDIR)/lib_hid_common/cli_history.o + $(PLUGDIR)/lib_hid_common/place.o @] -put /local/pcb/mod/CONF {$(PLUGDIR)/lib_hid_common/lib_hid_common_conf.h} +# dialog config is here because of hidlib: each hidlib user shall have its +# own dialogs plugin +put /local/pcb/mod/CONFFILE {dialogs.conf} +put /local/pcb/mod/CONF {$(PLUGDIR)/lib_hid_common/dialogs_conf.h} + switch /local/pcb/lib_hid_common/controls case {buildin} include /local/pcb/tmpasm/buildin; end; case {plugin} include /local/pcb/tmpasm/plugin; end; Index: trunk/src_plugins/lib_hid_common/cli_history.c =================================================================== --- trunk/src_plugins/lib_hid_common/cli_history.c (revision 24823) +++ trunk/src_plugins/lib_hid_common/cli_history.c (revision 24824) @@ -36,7 +36,7 @@ #include "safe_fs.h" #include "paths.h" -#define CFG lib_hid_common_conf.plugins.lib_hid_common.cli_history +#define CFG dialogs_conf.plugins.lib_hid_common.cli_history typedef struct hist_t { gdl_elem_t lst; Index: trunk/src_plugins/lib_hid_common/dialogs_conf.h =================================================================== --- trunk/src_plugins/lib_hid_common/dialogs_conf.h (nonexistent) +++ trunk/src_plugins/lib_hid_common/dialogs_conf.h (revision 24824) @@ -0,0 +1,37 @@ +#ifndef PCB_DIALOGS_CONF_H +#define PCB_DIALOGS_CONF_H + +#include "conf.h" + +/* dialog config is here because of hidlib: each hidlib user shall have its + own dialogs plugin */ + +typedef struct { + const struct plugins { + const struct dialogs { + const struct auto_save_window_geometry { + CFT_BOOLEAN to_design; + CFT_BOOLEAN to_project; + CFT_BOOLEAN to_user; + } auto_save_window_geometry; + const struct window_geometry { + const struct example_template { + CFT_INTEGER x; + CFT_INTEGER y; + CFT_INTEGER width; + CFT_INTEGER height; + } example_template; + } window_geometry; + } dialogs; + + const struct lib_hid_common { + const struct cli_history { + CFT_STRING file; /* Path to the history file (empty/unset means history is not preserved) */ + CFT_INTEGER slots; /* Number of commands to store in the history */ + } cli_history; + } lib_hid_common; + + } plugins; +} conf_dialogs_t; + +#endif Index: trunk/src_plugins/lib_hid_common/lib_hid_common.c =================================================================== --- trunk/src_plugins/lib_hid_common/lib_hid_common.c (revision 24823) +++ trunk/src_plugins/lib_hid_common/lib_hid_common.c (revision 24824) @@ -29,6 +29,7 @@ #include #include "plugins.h" #include "conf_hid.h" +#include "event.h" #include "grid_menu.h" #include "layer_menu.h" @@ -36,17 +37,18 @@ #include "cli_history.h" #include "util.c" #include "lead_user.h" +#include "place.h" #include "lib_hid_common.h" -#include "lib_hid_common_conf.h" +#include "dialogs_conf.h" -conf_lib_hid_common_t lib_hid_common_conf; +const conf_dialogs_t dialogs_conf; - static const char *grid_cookie = "lib_hid_common/grid"; static const char *layer_cookie = "lib_hid_common/layer"; static const char *rst_cookie = "lib_hid_common/route_style"; static const char *lead_cookie = "lib_hid_common/user_lead"; +static const char *wplc_cookie = "lib_hid_common/window_placement"; int pplg_check_ver_lib_hid_common(int ver_needed) { return 0; } @@ -60,8 +62,10 @@ pcb_event_unbind_allcookie(layer_cookie); pcb_event_unbind_allcookie(rst_cookie); pcb_event_unbind_allcookie(lead_cookie); + pcb_event_unbind_allcookie(wplc_cookie); conf_hid_unreg(grid_cookie); conf_hid_unreg(rst_cookie); + pcb_dialog_place_uninit(); conf_unreg_fields("plugins/lib_hid_common/"); } @@ -75,9 +79,12 @@ PCB_API_CHK_VER; #define conf_reg(field,isarray,type_name,cpath,cname,desc,flags) \ - conf_reg_field(lib_hid_common_conf, field,isarray,type_name,cpath,cname,desc,flags); -#include "lib_hid_common_conf_fields.h" + conf_reg_field(dialogs_conf, field,isarray,type_name,cpath,cname,desc,flags); +/*#include "lib_hid_common_conf_fields.h"*/ +#include "dialogs_conf_fields.h" + pcb_dialog_place_init(); + pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_grid_update_ev, NULL, grid_cookie); pcb_event_bind(PCB_EVENT_BOARD_CHANGED, pcb_layer_menu_update_ev, NULL, layer_cookie); pcb_event_bind(PCB_EVENT_LAYERS_CHANGED, pcb_layer_menu_update_ev, NULL, layer_cookie); @@ -87,6 +94,8 @@ pcb_event_bind(PCB_EVENT_GUI_INIT, pcb_rst_update_ev, NULL, rst_cookie); pcb_event_bind(PCB_EVENT_GUI_LEAD_USER, pcb_lead_user_ev, NULL, lead_cookie); pcb_event_bind(PCB_EVENT_GUI_DRAW_OVERLAY_XOR, pcb_lead_user_draw_ev, NULL, lead_cookie); + pcb_event_bind(PCB_EVENT_DAD_NEW_DIALOG, pcb_dialog_place, NULL, wplc_cookie); + pcb_event_bind(PCB_EVENT_DAD_NEW_GEO, pcb_dialog_resize, NULL, wplc_cookie); conf_id = conf_hid_reg(grid_cookie, NULL); memset(&ccb, 0, sizeof(ccb)); Index: trunk/src_plugins/lib_hid_common/lib_hid_common.h =================================================================== --- trunk/src_plugins/lib_hid_common/lib_hid_common.h (revision 24823) +++ trunk/src_plugins/lib_hid_common/lib_hid_common.h (revision 24824) @@ -1,3 +1,3 @@ -#include "lib_hid_common_conf.h" +#include "dialogs_conf.h" -extern conf_lib_hid_common_t lib_hid_common_conf; +extern const conf_dialogs_t dialogs_conf; Index: trunk/src_plugins/lib_hid_common/place.c =================================================================== --- trunk/src_plugins/lib_hid_common/place.c (nonexistent) +++ trunk/src_plugins/lib_hid_common/place.c (revision 24824) @@ -0,0 +1,316 @@ +/* + * COPYRIGHT + * + * pcb-rnd, interactive printed circuit board design + * Copyright (C) 2018,2019 Tibor 'Igor2' Palinkas + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Contact: + * Project page: http://repo.hu/projects/pcb-rnd + * lead developer: http://repo.hu/projects/pcb-rnd/contact.html + * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") + */ + +#include "config.h" +#include "event.h" +#include "compat_misc.h" +#include "error.h" +#include "conf.h" +#include "board.h" +#include "safe_fs.h" + +static const char *place_cookie = "dialogs/place"; + +#include "dialogs_conf.h" +extern const conf_dialogs_t dialogs_conf; + + +typedef struct { + int x, y, w, h; +} wingeo_t; + +wingeo_t wingeo_invalid = {0, 0, 0, 0}; + +typedef const char *htsw_key_t; +typedef wingeo_t htsw_value_t; +#define HT(x) htsw_ ## x +#define HT_INVALID_VALUE wingeo_invalid; +#include +#include +#undef HT +#include + +static htsw_t wingeo; + +static void pcb_dialog_store(const char *id, int x, int y, int w, int h) +{ + htsw_entry_t *e; + wingeo_t wg; + +/* pcb_trace("dialog place set: '%s' %d;%d %d*%d\n", id, x, y, w, h);*/ + + e = htsw_getentry(&wingeo, (char *)id); + if (e != NULL) { + e->value.x = x; + e->value.y = y; + e->value.w = w; + e->value.h = h; + return; + } + + wg.x = x; + wg.y = y; + wg.w = w; + wg.h = h; + htsw_set(&wingeo, pcb_strdup(id), wg); +} + + +void pcb_dialog_place(void *user_data, int argc, pcb_event_arg_t argv[]) +{ + const char *id; + int *geo; + htsw_entry_t *e; + + if ((argc < 3) || (argv[1].type != PCB_EVARG_PTR) || (argv[2].type != PCB_EVARG_STR)) + return; + + id = argv[2].d.s; + geo = argv[3].d.p; + + e = htsw_getentry(&wingeo, (char *)id); + if (e != NULL) { + geo[0] = e->value.x; + geo[1] = e->value.y; + geo[2] = e->value.w; + geo[3] = e->value.h; + } +/* pcb_trace("dialog place: %p '%s'\n", hid_ctx, id);*/ +} + +void pcb_dialog_resize(void *user_data, int argc, pcb_event_arg_t argv[]) +{ + if ((argc < 7) || (argv[1].type != PCB_EVARG_PTR) || (argv[2].type != PCB_EVARG_STR)) + return; + +/* hid_ctx = argv[1].d.p;*/ + pcb_dialog_store(argv[2].d.s, argv[3].d.i, argv[4].d.i, argv[5].d.i, argv[6].d.i); +} + +static vtp0_t cleanup_later; +static char *str_cleanup_later(const char *path) +{ + char *s = pcb_strdup(path); + vtp0_append(&cleanup_later, s); + return s; +} + +static void place_conf_set(conf_role_t role, const char *path, int val) +{ + static int dummy; + + if (conf_get_field(path) == NULL) + conf_reg_field_(&dummy, 1, CFN_INTEGER, str_cleanup_later(path), "", 0); + conf_setf(role, path, -1, "%d", val); +} + +static void place_conf_load(conf_role_t role, const char *path, int *val) +{ + conf_native_t *nat = conf_get_field(path); + conf_role_t crole; + static int dummy; + + if (conf_get_field(path) == NULL) { + conf_reg_field_(&dummy, 1, CFN_INTEGER, str_cleanup_later(path), "", 0); + conf_update(path, -1); + } + + nat = conf_get_field(path); + if ((nat == NULL) || (nat->prop->src == NULL) || (nat->prop->src->type != LHT_TEXT)) { + pcb_message(PCB_MSG_ERROR, "Can not load window geometry from invalid node for %s\n", path); + return; + } + + /* there are priorities which is hanled by conf merging. To make sure + only the final value is loaded, check if the final native's source + role matches the role that's being loaded. Else the currently loading + role is lower prio and didn't contribute to the final values and should + be ignored. */ + crole = conf_lookup_role(nat->prop->src); + if (crole != role) + return; + + /* need to atoi() directly from the lihata node because the native value + is dummy and shared among all nodes - cheaper to atoi than to do + a proper allocation for the native value. */ + *val = atoi(nat->prop->src->data.text.value); +} + +#define BASEPATH "plugins/dialogs/window_geometry/" +void pcb_wplc_load(conf_role_t role) +{ + char *end, *end2, path[128 + sizeof(BASEPATH)]; + lht_node_t *nd, *root; + lht_dom_iterator_t it; + int x, y, w, h; + + strcpy(path, BASEPATH); + end = path + strlen(BASEPATH); + + root = conf_lht_get_at(role, path, 0); + if (root == NULL) + return; + + for(nd = lht_dom_first(&it, root); nd != NULL; nd = lht_dom_next(&it)) { + int len; + if (nd->type != LHT_HASH) + continue; + len = strlen(nd->name); + if (len > 64) + continue; + memcpy(end, nd->name, len); + end[len] = '/'; + end2 = end + len+1; + + x = y = -1; + w = h = 0; + strcpy(end2, "x"); place_conf_load(role, path, &x); + strcpy(end2, "y"); place_conf_load(role, path, &y); + strcpy(end2, "width"); place_conf_load(role, path, &w); + strcpy(end2, "height"); place_conf_load(role, path, &h); + pcb_dialog_store(nd->name, x, y, w, h); + } +} + + +static void place_maybe_save(conf_role_t role, int force) +{ + htsw_entry_t *e; + char path[128 + sizeof(BASEPATH)]; + char *end, *end2; + + switch(role) { + case CFR_USER: if (!force && !dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_user) return; break; + case CFR_DESIGN: if (!force && !dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_design) return; break; + case CFR_PROJECT: if (!force && !dialogs_conf.plugins.dialogs.auto_save_window_geometry.to_project) return; break; + default: return; + } + + strcpy(path, BASEPATH); + end = path + strlen(BASEPATH); + for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) { + int len = strlen(e->key); + if (len > 64) + continue; + memcpy(end, e->key, len); + end[len] = '/'; + end2 = end + len+1; + + strcpy(end2, "x"); place_conf_set(role, path, e->value.x); + strcpy(end2, "y"); place_conf_set(role, path, e->value.y); + strcpy(end2, "width"); place_conf_set(role, path, e->value.w); + strcpy(end2, "height"); place_conf_set(role, path, e->value.h); + } + + + if (role != CFR_DESIGN) { + int r = conf_save_file(NULL, (PCB == NULL ? NULL : PCB->Filename), role, NULL); + if (r != 0) + pcb_message(PCB_MSG_ERROR, "Failed to save window geometry in %s\n", conf_role_name(role)); + } +} + +/* event handlers that run before the current pcb is saved to save win geo + in the board conf and after loading a new board to fetch window placement + info. */ +static void place_save_pre(void *user_data, int argc, pcb_event_arg_t argv[]) +{ + place_maybe_save(CFR_PROJECT, 0); + place_maybe_save(CFR_DESIGN, 0); +} + +static void place_load_post(void *user_data, int argc, pcb_event_arg_t argv[]) +{ + pcb_wplc_load(CFR_PROJECT); + pcb_wplc_load(CFR_DESIGN); +} + +void pcb_wplc_save_to_role(conf_role_t role) +{ + place_maybe_save(role, 1); +} + +int pcb_wplc_save_to_file(const char *fn) +{ + htsw_entry_t *e; + FILE *f; + + f = pcb_fopen(fn, "w"); + if (f == NULL) + return -1; + + fprintf(f, "li:pcb-rnd-conf-v1 {\n"); + fprintf(f, " ha:overwrite {\n"); + fprintf(f, " ha:plugins {\n"); + fprintf(f, " ha:dialogs {\n"); + fprintf(f, " ha:window_geometry {\n"); + + + for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) { + fprintf(f, " ha:%s {\n", e->key); + fprintf(f, " x=%d\n", e->value.x); + fprintf(f, " y=%d\n", e->value.x); + fprintf(f, " width=%d\n", e->value.w); + fprintf(f, " height=%d\n", e->value.h); + fprintf(f, " }\n"); + } + + fprintf(f, " }\n"); + fprintf(f, " }\n"); + fprintf(f, " }\n"); + fprintf(f, " }\n"); + fprintf(f, "}\n"); + fclose(f); + return 0; +} + +void pcb_dialog_place_uninit(void) +{ + htsw_entry_t *e; + int n; + + conf_unreg_fields(BASEPATH); + + place_maybe_save(CFR_USER, 0); + + for(e = htsw_first(&wingeo); e != NULL; e = htsw_next(&wingeo, e)) + free((char *)e->key); + htsw_uninit(&wingeo); + pcb_event_unbind_allcookie(place_cookie); + + for(n = 0; n < cleanup_later.used; n++) + free(cleanup_later.array[n]); + vtp0_uninit(&cleanup_later); +} + +void pcb_dialog_place_init(void) +{ + htsw_init(&wingeo, strhash, strkeyeq); + pcb_event_bind(PCB_EVENT_SAVE_PRE, place_save_pre, NULL, place_cookie); + pcb_event_bind(PCB_EVENT_LOAD_POST, place_load_post, NULL, place_cookie); + pcb_wplc_load(CFR_SYSTEM); + pcb_wplc_load(CFR_USER); +} Index: trunk/src_plugins/lib_hid_common/place.h =================================================================== --- trunk/src_plugins/lib_hid_common/place.h (nonexistent) +++ trunk/src_plugins/lib_hid_common/place.h (revision 24824) @@ -0,0 +1,10 @@ +#include "conf.h" +void pcb_wplc_load(conf_role_t role); + + +/*** for internal use ***/ +void pcb_dialog_place_uninit(void); +void pcb_dialog_place_init(void); +void pcb_dialog_resize(void *user_data, int argc, pcb_event_arg_t argv[]); +void pcb_dialog_place(void *user_data, int argc, pcb_event_arg_t argv[]); +