static void facet_view_selection_updated(GwySelection *selection, G_GNUC_UNUSED gint id, FacetsControls *controls) { GwyVectorLayer *layer; const gchar *key; gdouble theta, phi, x, y, q, xy[2]; gchar s[24]; q = gwy_container_get_double_by_name(controls->fdata, "/q"); gwy_selection_get_object(selection, 0, xy); x = xy[0] - G_SQRT2/q; y = xy[1] - G_SQRT2/q; xy_to_angles(x, y, &theta, &phi); g_snprintf(s, sizeof(s), "%.2f deg", 180.0/G_PI*theta); gtk_label_set_text(GTK_LABEL(controls->theta_label), s); controls->args->theta0 = theta; g_snprintf(s, sizeof(s), "%.2f deg", 180.0/G_PI*phi); gtk_label_set_text(GTK_LABEL(controls->phi_label), s); controls->args->phi0 = phi; if (!controls->in_update) { layer = gwy_data_view_get_top_layer(GWY_DATA_VIEW(controls->view)); key = gwy_vector_layer_get_selection_key(layer); selection = gwy_container_get_object_by_name(controls->mydata, key); if (gwy_selection_get_data(selection, NULL)) gwy_selection_clear(selection); } controls->computed = FALSE; }
static void prof_execute(ProfControls *controls, GwyContainer *data) { GwyGraphCurveModel *gcmodel; GwyGraphModel *gmodel; ProfArgs *args = controls->args; gchar *s; gint i, n; n = gwy_selection_get_data(controls->selection, NULL); g_return_if_fail(n); g_object_set(controls->gmodel, "label-visible", TRUE, NULL); if (!args->separate) { gwy_app_add_graph_or_curves(controls->gmodel, data, &args->target_graph, 1); return; } for (i = 0; i < n; i++) { gmodel = gwy_graph_model_new_alike(controls->gmodel); gcmodel = gwy_graph_model_get_curve(controls->gmodel, i); gcmodel = gwy_graph_curve_model_duplicate(gcmodel); gwy_graph_model_add_curve(gmodel, gcmodel); g_object_unref(gcmodel); g_object_get(gcmodel, "description", &s, NULL); g_object_set(gmodel, "title", s, NULL); g_free(s); gwy_app_data_browser_add_graph_model(gmodel, data, TRUE); g_object_unref(gmodel); } }
static void prof_selection_changed(ProfControls *controls, gint hint) { gint i, n; n = gwy_selection_get_data(controls->selection, NULL); if (hint < 0) { gwy_graph_model_remove_all_curves(controls->gmodel); for (i = 0; i < n; i++) prof_update_curve(controls, i); } else { prof_update_curve(controls, hint); } gtk_dialog_set_response_sensitive(GTK_DIALOG(controls->dialog), GTK_RESPONSE_OK, n > 0); }
/* XXX: This replicates straighten_path.c */ static GwyXY* rescale_points(GwySelection *selection, GwyDataField *dfield, gboolean realsquare, gdouble *pdx, gdouble *pdy, gdouble *pqx, gdouble *pqy) { gdouble dx, dy, qx, qy, h; GwyXY *points; guint n, i; dx = gwy_data_field_get_xmeasure(dfield); dy = gwy_data_field_get_ymeasure(dfield); h = MIN(dx, dy); if (realsquare) { qx = h/dx; qy = h/dy; dx = dy = h; } else qx = qy = 1.0; n = gwy_selection_get_data(selection, NULL); points = g_new(GwyXY, n); for (i = 0; i < n; i++) { gdouble xy[2]; gwy_selection_get_object(selection, i, xy); points[i].x = xy[0]/dx; points[i].y = xy[1]/dy; } *pdx = dx; *pdy = dy; *pqx = qx; *pqy = qy; return points; }
static void extract_path_do(GwyContainer *data, GwyDataField *dfield, gboolean realsquare, GwySelection *selection, const ExtrPathArgs *args) { GwyGraphModel *gmodel; GwySpline *spline; GwyXY *points, *tangents; GwySIUnit *xyunit; gdouble dx, dy, qx, qy, h, l, length, slackness; gdouble *xdata, *ydata; guint n, i; gboolean closed; /* This can only be satisfied in non-interactive use. Doing nothing is * the best option in this case. */ if (!selection || (n = gwy_selection_get_data(selection, NULL)) < 2) return; points = rescale_points(selection, dfield, realsquare, &dx, &dy, &qx, &qy); h = MIN(dx, dy); spline = gwy_spline_new_from_points(points, n); g_object_get(selection, "slackness", &slackness, "closed", &closed, NULL); gwy_spline_set_closed(spline, closed); gwy_spline_set_slackness(spline, slackness); g_free(points); length = gwy_spline_length(spline); /* This would give natural sampling for a straight line along some axis. */ n = GWY_ROUND(length + 1.0); points = g_new(GwyXY, n); tangents = g_new(GwyXY, n); xdata = g_new(gdouble, n); ydata = g_new(gdouble, n); gwy_spline_sample_uniformly(spline, points, tangents, n); qx *= dx; qy *= dy; for (i = 0; i < n; i++) { points[i].x *= qx; points[i].y *= qy; GWY_SWAP(gdouble, tangents[i].x, tangents[i].y); tangents[i].x *= qx; tangents[i].y *= -qy; l = sqrt(tangents[i].x*tangents[i].x + tangents[i].y*tangents[i].y); if (h > 0.0) { tangents[i].x /= l; tangents[i].y /= l; } xdata[i] = i/(n - 1.0)*length*h; } xyunit = gwy_data_field_get_si_unit_xy(dfield); if ((gmodel = create_graph_model(points, xdata, ydata, n, args->x, args->y))) { g_object_set(gmodel, "axis-label-left", _("Position"), "axis-label-bottom", _("Distance"), "si-unit-x", xyunit, "si-unit-y", xyunit, NULL); gwy_app_data_browser_add_graph_model(gmodel, data, TRUE); g_object_unref(gmodel); } if ((gmodel = create_graph_model(tangents, xdata, ydata, n, args->vx, args->vy))) { g_object_set(gmodel, "axis-label-left", _("Tangent"), "axis-label-bottom", _("Distance"), "si-unit-x", xyunit, NULL); gwy_app_data_browser_add_graph_model(gmodel, data, TRUE); g_object_unref(gmodel); } g_free(ydata); g_free(xdata); g_free(points); g_free(tangents); }
static gint extr_path_dialogue(ExtrPathArgs *args, GwySelection *selection) { GtkDialog *dialogue; GtkTable *table; GtkWidget *check, *label; ExtrPathControls controls; gint response, row, npts = 0; gchar buf[16]; gwy_clear(&controls, 1); controls.args = args; controls.selection = selection; if (selection) npts = gwy_selection_get_data(selection, NULL); dialogue = GTK_DIALOG(gtk_dialog_new_with_buttons(_("Extract " "Path Selection"), NULL, 0, NULL)); gtk_dialog_add_button(dialogue, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_add_button(dialogue, GTK_STOCK_OK, GTK_RESPONSE_OK); gtk_dialog_set_default_response(dialogue, GTK_RESPONSE_OK); gwy_help_add_to_proc_dialog(GTK_DIALOG(dialogue), GWY_HELP_DEFAULT); table = GTK_TABLE(gtk_table_new(5, 4, FALSE)); gtk_table_set_row_spacings(table, 2); gtk_table_set_col_spacings(table, 6); gtk_container_set_border_width(GTK_CONTAINER(table), 4); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialogue)->vbox), GTK_WIDGET(table), FALSE, FALSE, 4); row = 0; if (selection) { label = gtk_label_new(_("Number of path points:")); gtk_table_attach(table, label, 0, 1, row, row+1, GTK_FILL, 0, 0, 0); g_snprintf(buf, sizeof(buf), "%d", npts); label = gtk_label_new(buf); gtk_table_attach(table, label, 1, 3, row, row+1, GTK_FILL, 0, 0, 0); } else { label = gtk_label_new(_("There is no path selection.")); gtk_table_attach(table, label, 0, 4, row, row+1, GTK_FILL, 0, 0, 0); } row++; gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 8); check = create_output_checkbutton(_("X position"), &args->x, &controls); gtk_table_attach(table, check, 0, 4, row, row+1, GTK_FILL, 0, 0, 0); row++; check = create_output_checkbutton(_("Y position"), &args->y, &controls); gtk_table_attach(table, check, 0, 4, row, row+1, GTK_FILL, 0, 0, 0); row++; check = create_output_checkbutton(_("X tangent"), &args->vx, &controls); gtk_table_attach(table, check, 0, 4, row, row+1, GTK_FILL, 0, 0, 0); row++; check = create_output_checkbutton(_("Y tangent"), &args->vy, &controls); gtk_table_attach(table, check, 0, 4, row, row+1, GTK_FILL, 0, 0, 0); row++; gtk_dialog_set_response_sensitive(dialogue, GTK_RESPONSE_OK, npts > 1); gtk_widget_show_all(GTK_WIDGET(dialogue)); do { response = gtk_dialog_run(dialogue); switch (response) { case GTK_RESPONSE_CANCEL: case GTK_RESPONSE_DELETE_EVENT: gtk_widget_destroy(GTK_WIDGET(dialogue)); case GTK_RESPONSE_NONE: return FALSE; case GTK_RESPONSE_OK: break; default: g_assert_not_reached(); break; } } while (response != GTK_RESPONSE_OK); gtk_widget_destroy(GTK_WIDGET(dialogue)); return response == GTK_RESPONSE_OK; }