Index: excitation.c =================================================================== --- excitation.c (revision 24599) +++ excitation.c (revision 24600) @@ -28,11 +28,6 @@ #include "hid_dad.h" -static const char *pcb_openems_excitation_get(pcb_board_t *pcb) -{ - return "DUMMY_EXCITATION"; -} - #define MAX_EXC 16 typedef struct { @@ -42,6 +37,8 @@ typedef struct { PCB_DAD_DECL_NOINIT(dlg) int active; /* already open - allow only one instance */ + int wselector; + int selected; exc_data_t exc_data[MAX_EXC]; } exc_ctx_t; @@ -50,9 +47,9 @@ typedef struct { const char *name; void (*dad)(int idx); + char *(*get)(int idx); } exc_t; - /*** excitation "micro-plugins" ***/ #define I_FC 0 @@ -75,6 +72,20 @@ PCB_DAD_END(exc_ctx.dlg); } +static char *exc_gaus_get(int idx) +{ + int wf0, wfc; + + wf0 = exc_ctx.exc_data[idx].w[I_F0]; + wfc = exc_ctx.exc_data[idx].w[I_FC]; + + return pcb_strdup_printf( + "FDTD = SetGaussExcite(FDTD, %d, %d);", + exc_ctx.dlg[wf0].default_val.int_value, + exc_ctx.dlg[wfc].default_val.int_value + ); +} + #undef I_FC #undef I_F0 @@ -92,6 +103,18 @@ PCB_DAD_END(exc_ctx.dlg); } +static char *exc_sin_get(int idx) +{ + int wf0; + + wf0 = exc_ctx.exc_data[idx].w[I_F0]; + + return pcb_strdup_printf( + "FDTD = SetSinusExcite(FDTD, %d);", + exc_ctx.dlg[wf0].default_val.int_value + ); +} + #undef I_F0 /** custom **/ @@ -114,6 +137,20 @@ PCB_DAD_END(exc_ctx.dlg); } +static char *exc_cust_get(int idx) +{ + int wf0, wfunc; + + wf0 = exc_ctx.exc_data[idx].w[I_F0]; + wfunc = exc_ctx.exc_data[idx].w[I_FUNC]; + + return pcb_strdup_printf( + "FDTD = SetCustomExcite(FDTD, %d, %s)", + exc_ctx.dlg[wf0].default_val.int_value, + exc_ctx.dlg[wfunc].default_val.str_value + ); +} + #undef I_F0 #undef I_FUNC @@ -133,15 +170,28 @@ PCB_DAD_END(exc_ctx.dlg); } +static char *exc_user_get(int idx) +{ + int wscript; + pcb_hid_attribute_t *attr; + pcb_hid_text_t *txt; + + wscript = exc_ctx.exc_data[idx].w[I_SCRIPT]; + attr = &exc_ctx.dlg[wscript]; + txt = (pcb_hid_text_t *)attr->enumerations; + + return txt->hid_get_text(attr, exc_ctx.dlg_hid_ctx); +} + #undef I_SCRIPT /*** generic code ***/ static const exc_t excitations[] = { - { "gaussian", exc_gaus_dad }, - { "sinusoidal", exc_sin_dad }, - { "custom", exc_cust_dad }, + { "gaussian", exc_gaus_dad, exc_gaus_get }, + { "sinusoidal", exc_sin_dad, exc_sin_get }, + { "custom", exc_cust_dad, exc_cust_get }, - { "user-defined", exc_user_dad }, + { "user-defined", exc_user_dad, exc_user_get }, { NULL, NULL} }; @@ -210,3 +260,13 @@ pcb_dlg_exc(); return 0; } + +static char *pcb_openems_excitation_get(pcb_board_t *pcb) +{ + if ((exc_ctx.selected < 0) || (exc_ctx.selected >= sizeof(excitations)/sizeof(excitations[0]))) { + pcb_message(PCB_MSG_ERROR, "No excitation selected\n"); + return pcb_strdup("%% ERROR: no excitation selected\n"); + } + return excitations[exc_ctx.selected].get(exc_ctx.selected); +} + Index: export_openems.c =================================================================== --- export_openems.c (revision 24599) +++ export_openems.c (revision 24600) @@ -518,12 +518,16 @@ static void openems_write_mesh1(wctx_t *ctx) { pcb_mesh_t *mesh = pcb_mesh_get(MESH_NAME); + char *exc = pcb_openems_excitation_get(ctx->pcb); int n; fprintf(ctx->fsim, "%%%%%% Board mesh, part 1\n"); fprintf(ctx->fsim, "unit = 1.0e-3;\n"); fprintf(ctx->fsim, "FDTD = InitFDTD();\n"); - fprintf(ctx->fsim, "FDTD = %s;\n", pcb_openems_excitation_get(ctx->pcb)); + fprintf(ctx->fsim, "%% Excitation begin\n"); + fprintf(ctx->fsim, "%s\n", exc); + fprintf(ctx->fsim, "%% Excitation end\n"); + free(exc); if (mesh != NULL) {