Index: dlg_export.c =================================================================== --- dlg_export.c (revision 36609) +++ dlg_export.c (nonexistent) @@ -1,264 +0,0 @@ -/* - * COPYRIGHT - * - * pcb-rnd, interactive printed circuit board design - * Copyright (C) 2018,2022 Tibor 'Igor2' Palinkas - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Contact: - * Project page: http://repo.hu/projects/pcb-rnd - * lead developer: http://repo.hu/projects/pcb-rnd/contact.html - * mailing list: pcb-rnd (at) list.repo.hu (send "subscribe") - */ - -#include "config.h" -#include -#include -#include -#include -#include -#include -#include "dlg_export.h" - -typedef struct{ - RND_DAD_DECL_NOINIT(dlg) - int active; /* already open - allow only one instance */ - - int tabs, len; - - /* per exporter data */ - rnd_hid_t **hid; - const char **tab_name; - int **exp_attr; /* widget IDs of the attributes holding the actual data; outer array is indexed by exporter, inner array is by exporter option index from 0*/ - int *button; /* widget ID of the export button for a specific exporter */ - int *numo; /* number of exporter options */ - rnd_hid_attr_val_t **aa; /* original export argument arrays */ -} export_ctx_t; - -export_ctx_t export_ctx; - -static rnd_hid_attr_val_t *get_results(export_ctx_t *export_ctx, int id) -{ - rnd_hid_attr_val_t *r; - int *exp_attr, n, numo = export_ctx->numo[id]; - - r = malloc(sizeof(rnd_hid_attr_val_t) * numo); - - exp_attr = export_ctx->exp_attr[id]; - for(n = 0; n < numo; n++) { - int src = exp_attr[n]; - memcpy(&r[n], &(export_ctx->dlg[src].val), sizeof(rnd_hid_attr_val_t)); - } - return r; -} - -static void export_cb(void *hid_ctx, void *caller_data, rnd_hid_attribute_t *attr) -{ - export_ctx_t *export_ctx = caller_data; - rnd_hidlib_t *hl = rnd_gui->get_dad_hidlib(hid_ctx); - int h, wid; - - - wid = attr - export_ctx->dlg; - for(h = 0; h < export_ctx->len; h++) { - if (export_ctx->button[h] == wid) { - rnd_hid_t *render_save = rnd_render; - rnd_hid_attr_val_t *results = get_results(export_ctx, h); - - rnd_render = export_ctx->hid[h]; - rnd_event(hl, RND_EVENT_EXPORT_SESSION_BEGIN, NULL); - export_ctx->hid[h]->do_export(export_ctx->hid[h], results); - rnd_event(hl, RND_EVENT_EXPORT_SESSION_END, NULL); - rnd_render = render_save; - free(results); - rnd_message(RND_MSG_INFO, "Export done using exporter: %s\n", export_ctx->hid[h]->name); - goto done; - } - } - - rnd_message(RND_MSG_ERROR, "Internal error: can not find which exporter to call\n"); - done:; -} - -/* copy back the attribute values from the DAD dialog to exporter dialog so - that values are preserved */ -static void copy_attrs_back(export_ctx_t *ctx) -{ - int n, i; - - for(n = 0; n < ctx->len; n++) { - int *exp_attr = export_ctx.exp_attr[n]; - int numo = export_ctx.numo[n]; - rnd_hid_attr_val_t *args = export_ctx.aa[n]; - - for(i = 0; i < numo; i++) - memcpy(&args[i], &ctx->dlg[exp_attr[i]].val, sizeof(rnd_hid_attr_val_t)); - } -} - -static void export_close_cb(void *caller_data, rnd_hid_attr_ev_t ev) -{ - export_ctx_t *ctx = caller_data; - int n; - - copy_attrs_back(ctx); - - RND_DAD_FREE(ctx->dlg); - free(ctx->hid); - free(ctx->tab_name); - for(n = 0; n < export_ctx.len; n++) - free(ctx->exp_attr[n]); - free(ctx->exp_attr); - free(ctx->button); - free(ctx->numo); - free(ctx->aa); - memset(ctx, 0, sizeof(export_ctx_t)); /* reset all states to the initial - includes ctx->active = 0; */ -} - -static void pcb_dlg_export(const char *title, int exporters, int printers) -{ - rnd_hid_t **hids; - int n, i, *exp_attr; - rnd_hid_dad_buttons_t clbtn[] = {{"Close", 0}, {NULL, 0}}; - - if (export_ctx.active) - return; /* do not open another */ - - hids = rnd_hid_enumerate(); - for(n = 0, export_ctx.len = 0; hids[n] != NULL; n++) { - if (((exporters && hids[n]->exporter) || (printers && hids[n]->printer)) && (!hids[n]->hide_from_gui) && (hids[n]->argument_array != NULL)) - export_ctx.len++; - } - - if (export_ctx.len == 0) { - rnd_message(RND_MSG_ERROR, "Can not export: there are no export plugins available\n"); - return; - } - - export_ctx.tab_name = malloc(sizeof(char *) * (export_ctx.len+1)); - export_ctx.hid = malloc(sizeof(rnd_hid_t *) * (export_ctx.len)); - export_ctx.exp_attr = malloc(sizeof(int *) * (export_ctx.len)); - export_ctx.button = malloc(sizeof(int) * (export_ctx.len)); - export_ctx.numo = malloc(sizeof(int) * (export_ctx.len)); - export_ctx.aa = malloc(sizeof(rnd_hid_attr_val_t *) * (export_ctx.len)); - - for(i = n = 0; hids[n] != NULL; n++) { - if (((exporters && hids[n]->exporter) || (printers && hids[n]->printer)) && (!hids[n]->hide_from_gui)) { - if (hids[n]->argument_array == NULL) { - rnd_message(RND_MSG_ERROR, "%s can't export from GUI because of empty argument_array\n(please report this bug!)\n", hids[n]->name); - continue; - } - - export_ctx.tab_name[i] = hids[n]->name; - export_ctx.hid[i] = hids[n]; - i++; - } - } - - export_ctx.tab_name[i] = NULL; - - RND_DAD_BEGIN_VBOX(export_ctx.dlg); - RND_DAD_COMPFLAG(export_ctx.dlg, RND_HATF_EXPFILL); - RND_DAD_BEGIN_TABBED(export_ctx.dlg, export_ctx.tab_name); - RND_DAD_COMPFLAG(export_ctx.dlg, RND_HATF_LEFT_TAB|RND_HATF_EXPFILL); - export_ctx.tabs = RND_DAD_CURRENT(export_ctx.dlg); - for(n = 0; n < export_ctx.len; n++) { - int numo; - const rnd_export_opt_t *opts = export_ctx.hid[n]->get_export_options(export_ctx.hid[n], &numo); - rnd_hid_attr_val_t *args = export_ctx.hid[n]->argument_array; - export_ctx.numo[n] = numo; - export_ctx.aa[n] = args; - - if (numo < 1) { - RND_DAD_LABEL(export_ctx.dlg, "Exporter unavailable for direct export"); - continue; - } - RND_DAD_BEGIN_VBOX(export_ctx.dlg); - if (numo > 12) - RND_DAD_COMPFLAG(export_ctx.dlg, RND_HATF_SCROLL); - export_ctx.exp_attr[n] = exp_attr = malloc(sizeof(int) * numo); - for(i = 0; i < numo; i++) { - RND_DAD_BEGIN_HBOX(export_ctx.dlg) - - switch(opts[i].type) { - case RND_HATT_COORD: - RND_DAD_COORD(export_ctx.dlg); - RND_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); - RND_DAD_DEFAULT_NUM(export_ctx.dlg, args[i].crd); - break; - case RND_HATT_INTEGER: - RND_DAD_INTEGER(export_ctx.dlg); - RND_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); - RND_DAD_DEFAULT_NUM(export_ctx.dlg, args[i].lng); - break; - case RND_HATT_REAL: - RND_DAD_REAL(export_ctx.dlg); - RND_DAD_MINMAX(export_ctx.dlg, opts[i].min_val, opts[i].max_val); - RND_DAD_DEFAULT_NUM(export_ctx.dlg, args[i].dbl); - break; - case RND_HATT_UNIT: - RND_DAD_UNIT(export_ctx.dlg, RND_UNIT_METRIC | RND_UNIT_IMPERIAL); - RND_DAD_DEFAULT_NUM(export_ctx.dlg, args[i].lng); - break; - default: - if (RND_HATT_IS_COMPOSITE(opts[i].type)) { - rnd_hid_export_opt_func_t fnc = opts[i].default_val.func; - if (fnc != NULL) - fnc(RND_HIDEOF_DAD, &export_ctx, &opts[i], &args[i]); - } - else - RND_DAD_DUP_EXPOPT_VAL(export_ctx.dlg, &(opts[i]), args[i]); - } - exp_attr[i] = RND_DAD_CURRENT(export_ctx.dlg); - if (opts[i].name != NULL) - RND_DAD_LABEL(export_ctx.dlg, opts[i].name); - RND_DAD_END(export_ctx.dlg); - } - RND_DAD_LABEL(export_ctx.dlg, " "); /* ugly way of inserting some vertical spacing */ - RND_DAD_BEGIN_HBOX(export_ctx.dlg) - RND_DAD_LABEL(export_ctx.dlg, "Apply attributes and export: "); - RND_DAD_BUTTON(export_ctx.dlg, "Export!"); - export_ctx.button[n] = RND_DAD_CURRENT(export_ctx.dlg); - RND_DAD_CHANGE_CB(export_ctx.dlg, export_cb); - RND_DAD_END(export_ctx.dlg); - RND_DAD_END(export_ctx.dlg); - } - RND_DAD_END(export_ctx.dlg); - RND_DAD_BUTTON_CLOSES(export_ctx.dlg, clbtn); - RND_DAD_END(export_ctx.dlg); - - /* set up the context */ - export_ctx.active = 1; - - RND_DAD_NEW("export", export_ctx.dlg, title, &export_ctx, rnd_false, export_close_cb); -} - -const char pcb_acts_ExportGUI[] = "ExportGUI()\n"; -const char pcb_acth_ExportGUI[] = "Open the export dialog."; -fgw_error_t pcb_act_ExportGUI(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv) -{ - pcb_dlg_export("Export to file", 1, 0); - return 0; -} - -const char pcb_acts_PrintGUI[] = "PrintGUI()\n"; -const char pcb_acth_PrintGUI[] = "Open the print dialog."; -fgw_error_t pcb_act_PrintGUI(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv) -{ - pcb_dlg_export("Print", 0, 1); - return 0; -} - Index: dlg_export.h =================================================================== --- dlg_export.h (revision 36609) +++ dlg_export.h (nonexistent) @@ -1,7 +0,0 @@ -extern const char pcb_acts_ExportGUI[]; -extern const char pcb_acth_ExportGUI[]; -fgw_error_t pcb_act_ExportGUI(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv); - -extern const char pcb_acts_PrintGUI[]; -extern const char pcb_acth_PrintGUI[]; -fgw_error_t pcb_act_PrintGUI(fgw_arg_t *ores, int oargc, fgw_arg_t *oargv); Index: Plug.tmpasm =================================================================== --- Plug.tmpasm (revision 36609) +++ Plug.tmpasm (revision 36610) @@ -2,7 +2,6 @@ put /local/pcb/mod/OBJS [@ $(PLUGDIR)/dialogs/dialogs.o $(PLUGDIR)/dialogs/dlg_about.o - $(PLUGDIR)/dialogs/dlg_export.o $(PLUGDIR)/dialogs/dlg_flag_edit.o $(PLUGDIR)/dialogs/dlg_fontsel.o $(PLUGDIR)/dialogs/dlg_layer_binding.o Index: dialogs.c =================================================================== --- dialogs.c (revision 36609) +++ dialogs.c (revision 36610) @@ -36,6 +36,7 @@ #include "funchash_core.h" #include #include +#include /* from lib_hid_common */ extern conf_dialogs_t dialogs_conf; @@ -43,7 +44,6 @@ /* include them all for static inlines */ #include "dlg_test.c" #include "dlg_about.h" -#include "dlg_export.h" #include "dlg_flag_edit.h" #include "dlg_fontsel.h" #include "dlg_infobar.h" @@ -75,8 +75,10 @@ {"PadstackEdit", pcb_act_PadstackEdit, pcb_acth_PadstackEdit, pcb_acts_PadstackEdit}, {"About", pcb_act_About, pcb_acth_About, pcb_acts_About}, {"Pinout", pcb_act_Pinout, pcb_acth_Pinout, pcb_acts_Pinout}, - {"ExportGUI", pcb_act_ExportGUI, pcb_acth_ExportGUI, pcb_acts_ExportGUI}, - {"PrintGUI", pcb_act_PrintGUI, pcb_acth_PrintGUI, pcb_acts_PrintGUI}, + {"ExportGUI", rnd_act_ExportDialog, rnd_acth_ExportDialog, rnd_acts_ExportDialog}, + {"PrintGUI", rnd_act_PrintDialog, rnd_acth_PrintDialog, rnd_acts_PrintDialog}, + {"ExportDialog", rnd_act_ExportDialog, rnd_acth_ExportDialog, rnd_acts_ExportDialog}, + {"PrintDialog", rnd_act_PrintDialog, rnd_acth_PrintDialog, rnd_acts_PrintDialog}, {"GroupPropGui", pcb_act_GroupPropGui, pcb_acth_GroupPropGui, pcb_acts_GroupPropGui}, {"LayerPropGui", pcb_act_LayerPropGui, pcb_acth_LayerPropGui, pcb_acts_LayerPropGui}, {"pstklib", pcb_act_pstklib, pcb_acth_pstklib, pcb_acts_pstklib},