static GwyGLMaterial* gwy_gl_material_new(const gchar *name, const GwyRGBA *ambient, const GwyRGBA *diffuse, const GwyRGBA *specular, const GwyRGBA *emission, gdouble shininess, gboolean is_const) { GwyGLMaterial *gl_material; g_return_val_if_fail(name, NULL); gl_material = g_object_new(GWY_TYPE_GL_MATERIAL, "is-const", is_const, NULL); if (ambient) gl_material->ambient = *ambient; if (diffuse) gl_material->diffuse = *diffuse; if (specular) gl_material->specular = *specular; if (emission) gl_material->emission = *emission; if (shininess >= 0) gl_material->shininess = shininess; g_string_assign(GWY_RESOURCE(gl_material)->name, name); /* New non-const resources start as modified */ GWY_RESOURCE(gl_material)->is_modified = !is_const; return gl_material; }
void test_user_grain_value_inventory(void) { GwyUserGrainValue *usergrainvalue = make_test_grain_value(); GwyResource *resource = GWY_RESOURCE(usergrainvalue); const GwyInventoryItemType *item_type; GwyInventory *usergrainvalues = gwy_user_grain_values(); g_assert(GWY_IS_INVENTORY(usergrainvalues)); g_assert_cmpuint(gwy_inventory_size(usergrainvalues), ==, 0); item_type = gwy_inventory_get_item_type(usergrainvalues); g_assert(item_type); g_assert_cmpuint(item_type->type, ==, GWY_TYPE_USER_GRAIN_VALUE); g_assert(gwy_inventory_can_make_copies(usergrainvalues)); g_assert(!gwy_inventory_get_default_name(usergrainvalues)); g_assert(!gwy_resource_is_managed(resource)); g_assert(gwy_resource_is_modifiable(resource)); gwy_inventory_insert(usergrainvalues, G_OBJECT(usergrainvalue)); g_object_unref(usergrainvalue); g_assert(gwy_resource_is_managed(resource)); g_assert_cmpuint(gwy_inventory_size(usergrainvalues), ==, 1); item_type = gwy_resource_type_get_item_type(GWY_TYPE_USER_GRAIN_VALUE); g_assert(item_type); g_assert_cmpuint(item_type->type, ==, GWY_TYPE_USER_GRAIN_VALUE); usergrainvalue = gwy_user_grain_values_get(NULL); g_assert(GWY_IS_USER_GRAIN_VALUE(usergrainvalue)); resource = GWY_RESOURCE(usergrainvalue); g_assert_cmpstr(gwy_resource_get_name(resource), ==, "Bloat"); g_assert(gwy_resource_is_managed(resource)); g_assert(gwy_resource_is_modifiable(resource)); usergrainvalue = (GwyUserGrainValue*)gwy_inventory_get_default(usergrainvalues); g_assert(!usergrainvalue); gwy_inventory_copy(usergrainvalues, "Bloat", "Another"); g_assert_cmpuint(gwy_inventory_size(usergrainvalues), ==, 2); usergrainvalue = (GwyUserGrainValue*)gwy_inventory_get(usergrainvalues, "Another"); resource = GWY_RESOURCE(usergrainvalue); g_assert_cmpstr(gwy_resource_get_name(resource), ==, "Another"); gboolean modified; g_object_get(usergrainvalue, "modified", &modified, NULL); g_assert(gwy_resource_is_managed(resource)); g_assert(gwy_resource_is_modifiable(resource)); g_assert(modified); g_object_ref(usergrainvalue); gwy_inventory_delete(usergrainvalues, "Another"); g_assert(GWY_IS_USER_GRAIN_VALUE(usergrainvalue)); g_assert(!gwy_resource_is_managed(resource)); g_assert(gwy_resource_is_modifiable(resource)); g_object_unref(usergrainvalue); }
static gboolean gather_enabled(GtkTreeModel *model, G_GNUC_UNUSED GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) { GPtrArray *names = (GPtrArray*)user_data; GwyGrainValue *gvalue; gboolean enabled; gtk_tree_model_get(model, iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, &gvalue, GWY_GRAIN_VALUE_STORE_COLUMN_ENABLED, &enabled, -1); if (gvalue) { if (enabled) { const gchar *name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); g_ptr_array_add(names, (gpointer)name); } g_object_unref(gvalue); } return FALSE; }
static gboolean restore_enabled(GtkTreeModel *model, G_GNUC_UNUSED GtkTreePath *path, GtkTreeIter *iter, gpointer user_data) { const gchar **names = (const gchar**)user_data; GwyGrainValue *gvalue; if (!names) { gtk_tree_store_set(GTK_TREE_STORE(model), iter, GWY_GRAIN_VALUE_STORE_COLUMN_ENABLED, FALSE, -1); return FALSE; } gtk_tree_model_get(model, iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, &gvalue, -1); if (gvalue) { const gchar *name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); while (*names && !gwy_strequal(name, *names)) names++; gtk_tree_store_set(GTK_TREE_STORE(model), iter, GWY_GRAIN_VALUE_STORE_COLUMN_ENABLED, !!*names, -1); g_object_unref(gvalue); } return FALSE; }
void test_user_grain_value_serialize(void) { GwyUserGrainValue *usergrainvalue = make_test_grain_value(); serializable_duplicate(GWY_SERIALIZABLE(usergrainvalue), NULL); serializable_assign(GWY_SERIALIZABLE(usergrainvalue), NULL); GwyUserGrainValue *newusergrainvalue = (GwyUserGrainValue*)serialize_and_back(G_OBJECT(usergrainvalue), NULL); GwyResource *newresource = GWY_RESOURCE(newusergrainvalue); g_assert_cmpstr(gwy_resource_get_name(newresource), ==, "Bloat"); g_assert_cmpstr(gwy_user_grain_value_get_group(usergrainvalue), ==, "The Bloat Group"); g_assert_cmpstr(gwy_user_grain_value_get_formula(usergrainvalue), ==, "V_0/L_b0^3"); g_assert_cmpint(gwy_user_grain_value_get_power_x(usergrainvalue), ==, -1); g_assert_cmpint(gwy_user_grain_value_get_power_y(usergrainvalue), ==, 0); g_assert_cmpint(gwy_user_grain_value_get_power_z(usergrainvalue), ==, 1); g_assert_cmpuint(gwy_user_grain_value_get_same_units(usergrainvalue), ==, GWY_GRAIN_VALUE_SAME_UNITS_LATERAL); g_assert(!gwy_user_grain_value_get_is_angle(usergrainvalue)); g_object_unref(usergrainvalue); g_object_unref(newusergrainvalue); }
static void gwy_resource_get_property(GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { GwyResource *resource = GWY_RESOURCE(object); switch (prop_id) { case PROP_NAME: g_value_set_string(value, resource->name->str); break; case PROP_IS_CONST: g_value_set_boolean(value, resource->is_const); break; case PROP_IS_PREFERRED: g_value_set_boolean(value, resource->is_preferred); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec); break; } }
/** * gwy_gl_material_reset: * @gl_material: A GL material. * * Resets a GL material to default values. **/ void gwy_gl_material_reset(GwyGLMaterial *gl_material) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); gwy_gl_material_do_reset(gl_material); gwy_gl_material_changed(gl_material); }
/** * gwy_gl_material_set_ambient: * @gl_material: A GL material. * @ambient: Ambient reflectance. * * Sets the ambient reflectance of a GL material. **/ void gwy_gl_material_set_ambient(GwyGLMaterial *gl_material, const GwyRGBA *ambient) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); if (gwy_gl_material_set_rgba(ambient, &gl_material->ambient)) gwy_gl_material_changed(gl_material); }
/** * gwy_gl_material_set_specular: * @gl_material: A GL material. * @specular: Specular reflectance. * * Sets the specular reflectance of a GL material. **/ void gwy_gl_material_set_specular(GwyGLMaterial *gl_material, const GwyRGBA *specular) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); if (gwy_gl_material_set_rgba(specular, &gl_material->specular)) gwy_gl_material_changed(gl_material); }
/** * gwy_gl_material_set_emission: * @gl_material: A GL material. * @emission: Emission component. * * Sets the emission component of a GL material. **/ void gwy_gl_material_set_emission(GwyGLMaterial *gl_material, const GwyRGBA *emission) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); if (gwy_gl_material_set_rgba(emission, &gl_material->emission)) gwy_gl_material_changed(gl_material); }
/** * gwy_gl_material_set_diffuse: * @gl_material: A GL material. * @diffuse: Diffuse reflectance. * * Sets the diffuse reflectance of a GL material. **/ void gwy_gl_material_set_diffuse(GwyGLMaterial *gl_material, const GwyRGBA *diffuse) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); if (gwy_gl_material_set_rgba(diffuse, &gl_material->diffuse)) gwy_gl_material_changed(gl_material); }
static void gwy_layer_basic_gradient_disconnect(GwyLayerBasic *layer) { if (!layer->gradient) return; gwy_signal_handler_disconnect(layer->gradient, layer->gradient_id); gwy_resource_release(GWY_RESOURCE(layer->gradient)); layer->gradient = NULL; }
/** * gwy_gl_material_set_shininess: * @gl_material: A GL material. * @shininess: Shinniness value (in range 0..1, not 0..128). * * Sets the shininess value of a GL material. **/ void gwy_gl_material_set_shininess(GwyGLMaterial *gl_material, gdouble shininess) { g_return_if_fail(GWY_IS_GL_MATERIAL(gl_material)); g_return_if_fail(!GWY_RESOURCE(gl_material)->is_const); shininess = CLAMP(shininess, 0.0, 1.0); if (shininess != gl_material->shininess) { gl_material->shininess = shininess; gwy_gl_material_changed(gl_material); } }
static void axis_quantity_changed(GrainCrossControls *controls) { GtkTreeSelection *selection; GwyGraphModel *gmodel; GwyGrainValue *gvalue; GtkTreeModel *model; GtkTreeIter iter; gboolean ok; ok = TRUE; selection = gtk_tree_view_get_selection(controls->abscissa); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gtk_tree_model_get(model, &iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, &gvalue, -1); controls->args->abscissa = gwy_resource_get_name(GWY_RESOURCE(gvalue)); } else ok = FALSE; selection = gtk_tree_view_get_selection(controls->ordinate); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gtk_tree_model_get(model, &iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, &gvalue, -1); controls->args->ordinate = gwy_resource_get_name(GWY_RESOURCE(gvalue)); } else ok = FALSE; gmodel = create_corr_graph(controls->args, controls->dfield); gwy_graph_set_model(GWY_GRAPH(controls->graph), gmodel); g_object_unref(gmodel); gtk_dialog_set_response_sensitive(controls->dialog, GTK_RESPONSE_OK, ok); update_target_graphs(controls); }
static void gwy_layer_basic_destroy(GtkObject *object) { GwyLayerBasic *layer; layer = GWY_LAYER_BASIC(object); if (layer->gradient) { gwy_resource_release(GWY_RESOURCE(layer->gradient)); layer->gradient = NULL; } GTK_OBJECT_CLASS(gwy_layer_basic_parent_class)->destroy(object); }
static void gwy_layer_basic_gradient_connect(GwyLayerBasic *basic_layer) { GwyDataViewLayer *layer; const guchar *s = NULL; g_return_if_fail(!basic_layer->gradient); layer = GWY_DATA_VIEW_LAYER(basic_layer); if (basic_layer->gradient_key) gwy_container_gis_string(layer->data, basic_layer->gradient_key, &s); basic_layer->gradient = gwy_gradients_get_gradient(s); gwy_resource_use(GWY_RESOURCE(basic_layer->gradient)); basic_layer->gradient_id = g_signal_connect_swapped(basic_layer->gradient, "data-changed", G_CALLBACK(gwy_layer_basic_changed), layer); }
void test_user_grain_value_save(void) { GwyUserGrainValue *usergrainvalue = make_test_grain_value(); GwyResource *resource = GWY_RESOURCE(usergrainvalue); GError *error = NULL; gwy_resource_set_filename(resource, "Bloat3"); g_assert(gwy_resource_save(resource, &error)); g_assert_no_error(error); g_test_queue_destroy((GDestroyNotify)g_unlink, "Bloat3"); resource_check_file(resource, "Bloat3"); GWY_OBJECT_UNREF(usergrainvalue); user_grain_value_load_check("Bloat3", "Bloat", "The Bloat Group", "V_0/L_b0^3", -1, 0, 1, GWY_GRAIN_VALUE_SAME_UNITS_LATERAL, FALSE); }
static GSList* construct_bases_radio(GwyGrainQuantity current, GCallback callback, gpointer cbdata) { enum { n = G_N_ELEMENTS(level_grains_bases) }; GwyEnum entries[n]; guint i; for (i = 0; i < n; i++) { GwyGrainQuantity q = level_grains_bases[i]; GwyGrainValue *value = gwy_grain_values_get_builtin_grain_value(q); entries[i].value = q; entries[i].name = gwy_resource_get_name(GWY_RESOURCE(value)); } return gwy_radio_buttons_create(entries, n, callback, cbdata, current); }
static gpointer gwy_gl_material_copy(gpointer item) { GwyGLMaterial *gl_material, *copy; g_return_val_if_fail(GWY_IS_GL_MATERIAL(item), NULL); gl_material = GWY_GL_MATERIAL(item); copy = gwy_gl_material_new(gwy_resource_get_name(GWY_RESOURCE(item)), &gl_material->ambient, &gl_material->diffuse, &gl_material->specular, &gl_material->emission, gl_material->shininess, FALSE); return copy; }
static void threshold_changed(GFilterControls *controls, GtkAdjustment *adj) { GFilterArgs *args = controls->args; GwyInventory *inventory; GwyGrainValue *gvalue; GtkEntry *entry; const gchar *name; gboolean is_upper; guint id, i, k; gdouble *v; gdouble value; gchar *s; if (controls->in_init) return; id = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(adj), "id")); is_upper = id & IS_UPPER; id &= ~IS_UPPER; k = gwy_adjustment_get_int(adj); inventory = gwy_grain_values(); gvalue = gwy_inventory_get_item(inventory, args->ranges[id].quantity); g_return_if_fail(gvalue); name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); i = gwy_inventory_get_item_position(inventory, args->ranges[id].quantity); v = g_ptr_array_index(args->sortedvaluedata, i); value = v[k]; s = g_strdup_printf("%.*f", controls->vf[id]->precision, value/controls->vf[id]->magnitude); if (is_upper) entry = GTK_ENTRY(controls->upper_entry[id]); else entry = GTK_ENTRY(controls->lower_entry[id]); gtk_entry_set_text(entry, s); g_free(s); set_threshold_value(args, id, name, value, is_upper); gfilter_invalidate(controls); }
static GwyUserGrainValue* make_test_grain_value(void) { GwyUserGrainValue *usergrainvalue = gwy_user_grain_value_new(); GwyResource *resource = GWY_RESOURCE(usergrainvalue); gwy_resource_set_name(resource, "Bloat"); g_assert_cmpstr(gwy_resource_get_name(resource), ==, "Bloat"); gwy_user_grain_value_set_group(usergrainvalue, "The Bloat Group"); g_assert_cmpstr(gwy_user_grain_value_get_group(usergrainvalue), ==, "The Bloat Group"); gwy_user_grain_value_set_symbol(usergrainvalue, "Blt₃"); g_assert_cmpstr(gwy_user_grain_value_get_symbol(usergrainvalue), ==, "Blt₃"); gwy_user_grain_value_set_ident(usergrainvalue, "Blt_3"); g_assert_cmpstr(gwy_user_grain_value_get_ident(usergrainvalue), ==, "Blt_3"); g_assert(gwy_user_grain_value_set_formula(usergrainvalue, "V_0/L_b0^3", NULL)); g_assert_cmpstr(gwy_user_grain_value_get_formula(usergrainvalue), ==, "V_0/L_b0^3"); gwy_user_grain_value_set_power_x(usergrainvalue, -1); g_assert_cmpint(gwy_user_grain_value_get_power_x(usergrainvalue), ==, -1); gwy_user_grain_value_set_power_y(usergrainvalue, 0); g_assert_cmpint(gwy_user_grain_value_get_power_y(usergrainvalue), ==, 0); gwy_user_grain_value_set_power_z(usergrainvalue, 1); g_assert_cmpint(gwy_user_grain_value_get_power_z(usergrainvalue), ==, 1); gwy_user_grain_value_set_same_units(usergrainvalue, GWY_GRAIN_VALUE_SAME_UNITS_LATERAL); g_assert_cmpuint(gwy_user_grain_value_get_same_units(usergrainvalue), ==, GWY_GRAIN_VALUE_SAME_UNITS_LATERAL); g_assert(!gwy_user_grain_value_get_is_angle(usergrainvalue)); return usergrainvalue; }
static void set_adjustment_to_grain_value(GFilterControls *controls, GwyGrainValue *gvalue, GtkAdjustment *adj, gdouble value) { GFilterArgs *args = controls->args; GwyInventory *inventory; const gchar *name; guint k, i; const gdouble *v; inventory = gwy_grain_values(); name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); i = gwy_inventory_get_item_position(inventory, name); v = g_ptr_array_index(args->sortedvaluedata, i); k = bisect_lower(v, args->nuniqvalues[i], value); /* XXX: This is approximate, but maybe sufficient. */ gtk_adjustment_set_value(adj, k); }
static void gfilter_sanitize_args(GFilterArgs *args) { GwyInventory *inventory; guint i; inventory = gwy_grain_values(); args->logical = MIN(args->logical, GRAIN_LOGICAL_NTYPES); for (i = 0; i < NQUANTITIES; i++) { RangeRecord *rr = args->ranges + i; GwyGrainValue *gvalue; if ((gvalue = gwy_inventory_get_item(inventory, rr->quantity))) rr->quantity = gwy_resource_get_name(GWY_RESOURCE(gvalue)); else rr->quantity = gfilter_defaults.ranges[i].quantity; /* The actual range is restored later from range_history. */ } args->update = !!args->update; }
static void threshold_activated(GFilterControls *controls, GtkEntry *entry) { GFilterArgs *args = controls->args; GwyInventory *inventory; GwyGrainValue *gvalue; GtkAdjustment *adj; guint id; gboolean is_upper; const gchar *s, *name; gdouble value; if (controls->in_init) return; id = GPOINTER_TO_UINT(g_object_get_data(G_OBJECT(entry), "id")); is_upper = id & IS_UPPER; id &= ~IS_UPPER; inventory = gwy_grain_values(); gvalue = gwy_inventory_get_item(inventory, args->ranges[id].quantity); g_return_if_fail(gvalue); name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); s = gtk_entry_get_text(entry); value = g_strtod(s, NULL) * controls->vf[id]->magnitude; if (is_upper) adj = GTK_ADJUSTMENT(controls->upper[id]); else adj = GTK_ADJUSTMENT(controls->lower[id]); controls->in_init = TRUE; set_adjustment_to_grain_value(controls, gvalue, adj, value); controls->in_init = FALSE; set_threshold_value(args, id, name, value, is_upper); gfilter_invalidate(controls); }
static void render_name(G_GNUC_UNUSED GtkTreeViewColumn *column, GtkCellRenderer *renderer, GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data) { GtkTreeView *treeview = (GtkTreeView*)user_data; PangoEllipsizeMode ellipsize; PangoWeight weight; GwyGrainValue *gvalue; GwyGrainValueGroup group; const gchar *name; GdkColor color; gtk_tree_model_get(model, iter, GWY_GRAIN_VALUE_STORE_COLUMN_ITEM, &gvalue, GWY_GRAIN_VALUE_STORE_COLUMN_GROUP, &group, -1); ellipsize = gvalue ? PANGO_ELLIPSIZE_END : PANGO_ELLIPSIZE_NONE; weight = gvalue ? PANGO_WEIGHT_NORMAL : PANGO_WEIGHT_BOLD; text_color(treeview, gvalue, &color); if (gvalue) { name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); if (group != GWY_GRAIN_VALUE_GROUP_USER) name = gettext(name); g_object_unref(gvalue); } else name = gettext(gwy_grain_value_group_name(group)); g_object_set(renderer, "ellipsize", ellipsize, "weight", weight, "markup", name, "foreground-gdk", &color, NULL); }
static GwyGraphModel* create_corr_graph(GrainCrossArgs *args, GwyDataField *dfield) { GwyGraphCurveModel *cmodel; GwyGraphModel *gmodel; GwyGrainValue *gvalues[2]; gdouble *xdata, *ydata, *bothdata, *rdata[2]; GwySIUnit *siunitxy, *siunitz, *siunitx, *siunity; const gchar *title; gint i; gvalues[0] = gwy_grain_values_get_grain_value(args->abscissa); gvalues[1] = gwy_grain_values_get_grain_value(args->ordinate); bothdata = g_new(gdouble, 4*args->ngrains + 2); rdata[0] = xdata = bothdata + 2*args->ngrains; rdata[1] = ydata = bothdata + 3*args->ngrains + 1; gwy_grain_values_calculate(2, gvalues, rdata, dfield, args->ngrains, args->grains); for (i = 0; i < args->ngrains; i++) { bothdata[2*i + 0] = xdata[i+1]; bothdata[2*i + 1] = ydata[i+1]; } qsort(bothdata, args->ngrains, 2*sizeof(gdouble), compare_doubles); for (i = 0; i < args->ngrains; i++) { xdata[i] = bothdata[2*i + 0]; ydata[i] = bothdata[2*i + 1]; } gmodel = gwy_graph_model_new(); cmodel = gwy_graph_curve_model_new(); gwy_graph_model_add_curve(gmodel, cmodel); g_object_unref(cmodel); siunitxy = gwy_data_field_get_si_unit_xy(dfield); siunitz = gwy_data_field_get_si_unit_z(dfield); siunitx = gwy_si_unit_power_multiply (siunitxy, gwy_grain_value_get_power_xy(gvalues[0]), siunitz, gwy_grain_value_get_power_z(gvalues[0]), NULL); siunity = gwy_si_unit_power_multiply (siunitxy, gwy_grain_value_get_power_xy(gvalues[1]), siunitz, gwy_grain_value_get_power_z(gvalues[1]), NULL); /* FIXME */ title = gettext(gwy_resource_get_name(GWY_RESOURCE(gvalues[1]))); g_object_set (gmodel, "title", title, "axis-label-left", gwy_grain_value_get_symbol_markup(gvalues[1]), "axis-label-bottom", gwy_grain_value_get_symbol_markup(gvalues[0]), "si-unit-x", siunitx, "si-unit-y", siunity, NULL); g_object_unref(siunitx); g_object_unref(siunity); g_object_set(cmodel, "description", title, "mode", GWY_GRAPH_CURVE_POINTS, NULL); gwy_graph_curve_model_set_data(cmodel, xdata, ydata, args->ngrains); g_free(bothdata); return gmodel; }
static void cnew(G_GNUC_UNUSED GwyContainer *data, GwyRunType run) { GwyDataField *dfield; CNewArgs args; gboolean ok; gint oldid, i, j, k, n; GwyCalibration *calibration; GwyCalData *caldata = NULL, *old; gchar *filename; gchar *contents; gsize len = 0; GError *err = NULL; gsize pos = 0; GString *str; gdouble *x, *y, *z, *xunc, *yunc, *zunc, *xerr, *yerr, *zerr; FILE *fh; g_return_if_fail(run & CNEW_RUN_MODES); gwy_app_data_browser_get_current(GWY_APP_DATA_FIELD, &dfield, GWY_APP_DATA_FIELD_ID, &oldid, 0); g_return_if_fail(dfield); cnew_load_args(gwy_app_settings_get(), &args); if (run == GWY_RUN_INTERACTIVE) { ok = cnew_dialog(&args, dfield); cnew_save_args(gwy_app_settings_get(), &args); if (!ok) return; } /*create the caldata*/ caldata = gwy_caldata_new(8); x = gwy_caldata_get_x(caldata); y = gwy_caldata_get_y(caldata); z = gwy_caldata_get_z(caldata); xerr = gwy_caldata_get_xerr(caldata); yerr = gwy_caldata_get_yerr(caldata); zerr = gwy_caldata_get_zerr(caldata); xunc = gwy_caldata_get_xunc(caldata); yunc = gwy_caldata_get_yunc(caldata); zunc = gwy_caldata_get_zunc(caldata); gwy_caldata_set_si_unit_x(caldata, gwy_data_field_get_si_unit_xy(dfield)); gwy_caldata_set_si_unit_y(caldata, gwy_data_field_get_si_unit_xy(dfield)); gwy_caldata_set_si_unit_z(caldata, gwy_data_field_get_si_unit_z(dfield)); n = 0; for (i=0; i<2; i++) { for (j=0; j<2; j++) { for (k=0; k<2; k++) { if (i) x[n] = args.xrange_from; else x[n] = args.xrange_to; if (j) y[n] = args.yrange_from; else y[n] = args.yrange_to; if (k) z[n] = args.zrange_from; else z[n] = args.zrange_to; if (i) xerr[n] = (args.xrange_to-args.xrange_from)*(args.xmult-1); else xerr[n] = 0; if (j) yerr[n] = (args.yrange_to-args.yrange_from)*(args.ymult-1); else yerr[n] = 0; if (k) zerr[n] = (args.zrange_to-args.zrange_from)*(args.zmult-1); else zerr[n] = 0; xunc[n] = args.xunc; yunc[n] = args.yunc; zunc[n] = args.zunc; n++; } } } if (args.duplicate == DUPLICATE_APPEND && (calibration = gwy_inventory_get_item(gwy_calibrations(), args.name))) { filename = g_build_filename(gwy_get_user_dir(), "caldata", calibration->filename, NULL); if (!g_file_get_contents(filename, &contents, &len, &err) || !len) { g_warning("Error loading file: %s", err->message); g_clear_error(&err); return; } else { if (len) old = GWY_CALDATA(gwy_serializable_deserialize(contents, len, &pos)); g_free(contents); } gwy_caldata_append(old, caldata); g_object_unref(caldata); caldata = old; } gwy_caldata_set_range(caldata, args.xrange_from, args.xrange_to, args.yrange_from, args.yrange_to, args.zrange_from, args.zrange_to); //printf("Saving %g %g %g %g\n", args.xrange_from, args.xrange_to, args.yrange_from, args.yrange_to); /*now create and save the resource*/ if ((calibration = GWY_CALIBRATION(gwy_inventory_get_item(gwy_calibrations(), args.name)))==NULL) { calibration = gwy_calibration_new(args.name, g_strconcat(args.name, ".dat", NULL)); gwy_inventory_insert_item(gwy_calibrations(), calibration); g_object_unref(calibration); } calibration->caldata = caldata; filename = gwy_resource_build_filename(GWY_RESOURCE(calibration)); if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { g_mkdir(g_build_filename(gwy_get_user_dir(), "calibrations", NULL), 0700); } fh = gwy_fopen(filename, "wb"); if (!fh) { g_warning(_("Cannot save preset: %s"), filename); g_free(filename); return; } g_free(filename); str = gwy_resource_dump(GWY_RESOURCE(calibration)); fwrite(str->str, 1, str->len, fh); fclose(fh); g_string_free(str, TRUE); gwy_resource_data_saved(GWY_RESOURCE(calibration)); gwy_resource_data_changed(GWY_RESOURCE(calibration)); /*now save the calibration data*/ //gwy_caldata_debug(caldata, "Saving: "); gwy_caldata_save_data(caldata, calibration->filename); }
static void set_up_quantity(GFilterControls *controls, GwyGrainValue *gvalue, guint id) { GFilterArgs *args = controls->args; GwyInventory *inventory; GwyDataField *dfield; RangeRecord *rr; const gchar *name; const gdouble *v; gchar *s, *t; gdouble vmin, vmax, lower = -G_MAXDOUBLE, upper = G_MAXDOUBLE; GwySIUnit *siunit, *siunitxy, *siunitz; gboolean was_in_init = controls->in_init; guint i, nuniq; controls->in_init = TRUE; name = gwy_resource_get_name(GWY_RESOURCE(gvalue)); args->ranges[id].quantity = name; /* TRANSLATORS: %c is replaced with quantity label A, B or C. */ s = g_strdup_printf(_("Condition %c: %s"), 'A' + id, name); t = g_strconcat("<b>", s, "</b>", NULL); gtk_label_set_markup(GTK_LABEL(controls->header[id]), t); g_free(t); g_free(s); rr = g_hash_table_lookup(args->ranges_history, (gpointer)name); if (rr) { lower = rr->lower; upper = rr->upper; } inventory = gwy_grain_values(); i = gwy_inventory_get_item_position(inventory, name); nuniq = args->nuniqvalues[i]; v = g_ptr_array_index(args->sortedvaluedata, i); vmin = v[0]; vmax = v[nuniq-1]; lower = CLAMP(lower, vmin, vmax); upper = CLAMP(upper, vmin, vmax); gtk_adjustment_set_upper(GTK_ADJUSTMENT(controls->lower[id]), nuniq-1); gtk_adjustment_set_upper(GTK_ADJUSTMENT(controls->upper[id]), nuniq-1); dfield = gwy_container_get_object_by_name(controls->mydata, "/0/data"); siunitxy = gwy_data_field_get_si_unit_xy(dfield); siunitz = gwy_data_field_get_si_unit_z(dfield); siunit = gwy_si_unit_power_multiply(siunitxy, gwy_grain_value_get_power_xy(gvalue), siunitz, gwy_grain_value_get_power_z(gvalue), NULL); gwy_si_unit_get_format_with_digits(siunit, GWY_SI_UNIT_FORMAT_VFMARKUP, MAX(fabs(vmin), fabs(vmax)), 4, controls->vf[id]); g_object_unref(siunit); /* Special-case the pixel area format. */ if (gwy_strequal(name, "Pixel area")) { controls->vf[id]->magnitude = 1.0; controls->vf[id]->precision = 0; gwy_si_unit_value_format_set_units(controls->vf[id], ""); } gtk_label_set_markup(GTK_LABEL(controls->lower_units[id]), controls->vf[id]->units); gtk_label_set_markup(GTK_LABEL(controls->upper_units[id]), controls->vf[id]->units); args->ranges[id].quantity = name; args->ranges[id].lower = lower; args->ranges[id].upper = upper; set_adjustment_to_grain_value(controls, gvalue, GTK_ADJUSTMENT(controls->lower[id]), lower); set_adjustment_to_grain_value(controls, gvalue, GTK_ADJUSTMENT(controls->upper[id]), upper); s = g_strdup_printf("%.*f", controls->vf[id]->precision, lower/controls->vf[id]->magnitude); gtk_entry_set_text(GTK_ENTRY(controls->lower_entry[id]), s); g_free(s); s = g_strdup_printf("%.*f", controls->vf[id]->precision, upper/controls->vf[id]->magnitude); gtk_entry_set_text(GTK_ENTRY(controls->upper_entry[id]), s); g_free(s); /* XXX: We might have modified the range by CLAMP(). Store the new one * right here? Pro: consistency. Con: the user did not do anything, * he just may be browsing. */ controls->in_init = was_in_init; gfilter_invalidate(controls); }
static void gfilter_load_args(GwyContainer *container, GFilterArgs *args) { GwyInventory *inventory; gchar *filename, *buffer; gsize size; guint i; inventory = gwy_grain_values(); *args = gfilter_defaults; gwy_container_gis_boolean_by_name(container, update_key, &args->update); gwy_container_gis_int32_by_name(container, expanded_key, &args->expanded); gwy_container_gis_enum_by_name(container, logical_key, &args->logical); for (i = 0; i < NQUANTITIES; i++) { RangeRecord *rr = args->ranges + i; gchar buf[sizeof(quantity_key) + 10]; g_snprintf(buf, sizeof(buf), "%s%u", quantity_key, i+1); gwy_container_gis_string_by_name(container, buf, (const guchar**)&rr->quantity); } args->ranges_history = g_hash_table_new_full(g_str_hash, g_str_equal, NULL, range_record_free); filename = g_build_filename(gwy_get_user_dir(), "grain_filter", "ranges", NULL); if (g_file_get_contents(filename, &buffer, &size, NULL)) { gchar *p = buffer, *line; for (line = gwy_str_next_line(&p); line; line = gwy_str_next_line(&p)) { g_strstrip(line); if (*line) { GwyGrainValue *gvalue; RangeRecord *rr; gchar *s = line, *end; gdouble lower, upper; lower = g_ascii_strtod(s, &end); s = end; upper = g_ascii_strtod(s, &end); if (end == s) { g_warning("Invalid grain_filter range record: %s.", line); continue; } s = end; g_strstrip(s); if (!(gvalue = gwy_inventory_get_item(inventory, s))) { g_warning("Invalid grain_filter range record: %s.", line); continue; } rr = g_slice_new(RangeRecord); rr->lower = lower; rr->upper = upper; rr->quantity = gwy_resource_get_name(GWY_RESOURCE(gvalue)); g_hash_table_insert(args->ranges_history, (gpointer)rr->quantity, rr); } } g_free(buffer); } g_free(filename); gfilter_sanitize_args(args); }
static void gwy_gl_material_changed(GwyGLMaterial *gl_material) { gwy_resource_data_changed(GWY_RESOURCE(gl_material)); }