![]() |
![]() |
![]() |
Gwyddion Module Library Reference Manual | ![]() |
---|
Minimal ModuleMinimal Module — Dissection of a minimal Gwyddion data processing module |
In this section we will describe a minimal Gwyddion data-processing module. It provides a function to invert values in a channel about zero. The complete module code is:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
#include <libgwyddion/gwymacros.h> #include <libprocess/datafield.h> #include <libgwymodule/gwymodule-process.h> #include <libgwydgets/gwystock.h> #include <app/gwyapp.h> #define INVERT_VALUE_RUN_MODES GWY_RUN_IMMEDIATE static gboolean module_register(void); static void my_invert_value(GwyContainer *data, GwyRunType run); static GwyModuleInfo module_info = { GWY_MODULE_ABI_VERSION, &module_register, N_("Inverts data value."), "J. Random Hacker <hacker.jr@example.org>", "1.0", "Bit Rot Inc.", "2006", }; GWY_MODULE_QUERY(module_info) static gboolean module_register(void) { gwy_process_func_register("my_invert_value", (GwyProcessFunc)&my_invert_value, N_("/_Test/_Invert Value"), GWY_STOCK_VALUE_INVERT, INVERT_VALUE_RUN_MODES, GWY_MENU_FLAG_DATA, N_("Invert data value about origin")); return TRUE; } static void my_invert_value(GwyContainer *data, GwyRunType run) { GwyDataField *dfield; GQuark quark; g_return_if_fail(run & INVERT_VALUE_RUN_MODES); gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, GWY_APP_DATA_FIELD_KEY, &quark, 0); gwy_app_undo_qcheckpointv(data, 1, &quark); gwy_data_field_multiply(dfield, -1.0); gwy_data_field_data_changed(dfield); } |
1 2 3 4 5 |
#include <libgwyddion/gwymacros.h> #include <libprocess/datafield.h> #include <libgwymodule/gwymodule-process.h> #include <libgwydgets/gwystock.h> #include <app/gwyapp.h> |
1 2 3 |
static gboolean module_register(void); static void my_invert_value(GwyContainer *data, GwyRunType run); |
1 |
#define INVERT_VALUE_RUN_MODES GWY_RUN_IMMEDIATE |
1 2 3 4 5 6 7 8 9 |
static GwyModuleInfo module_info = { GWY_MODULE_ABI_VERSION, &module_register, N_("Inverts data value."), "J. Random Hacker <hacker.jr@example.org>", "1.0", "Bit Rot Inc.", "2006", }; |
1 |
GWY_MODULE_QUERY(module_info) |
1 2 3 4 5 6 7 8 9 10 11 12 13 |
static gboolean module_register(void) { gwy_process_func_register("my_invert_value", (GwyProcessFunc)&my_invert_value, N_("/_Test/_Invert Value"), GWY_STOCK_VALUE_INVERT, INVERT_VALUE_RUN_MODES, GWY_MENU_FLAG_DATA, N_("Invert data value about origin")); return TRUE; } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
static void my_invert_value(GwyContainer *data, GwyRunType run) { GwyDataField *dfield; GQuark quark; g_return_if_fail(run & INVERT_VALUE_RUN_MODES); gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, GWY_APP_DATA_FIELD_KEY, &quark, 0); gwy_app_undo_qcheckpointv(data, 1, &quark); gwy_data_field_multiply(dfield, -1.0); gwy_data_field_data_changed(dfield); } |