From 6b9db822b0e88b4a3a381b97de784327ba5c4c66 Mon Sep 17 00:00:00 2001 From: Cristina Suteu Date: Thu, 12 Oct 2023 14:42:44 +0300 Subject: [PATCH 1/4] glade/oscplot: expand channel selection in save_as dialog Signed-off-by: Cristina Suteu --- glade/oscplot.glade | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/glade/oscplot.glade b/glade/oscplot.glade index ea71eb3e..5aac49cf 100644 --- a/glade/oscplot.glade +++ b/glade/oscplot.glade @@ -1716,7 +1716,7 @@ - False + True True 3 From 282374059d7c82e555071f02fc55cfa477ae7fb3 Mon Sep 17 00:00:00 2001 From: Cristina Suteu Date: Thu, 12 Oct 2023 16:37:59 +0300 Subject: [PATCH 2/4] oscplot: fix save as png correctly get window allocation pass x and y coordinates to gdk_pixbuf_get_from_window Signed-off-by: Cristina Suteu --- oscplot.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/oscplot.c b/oscplot.c index d30b9360..1a7c5a0e 100644 --- a/oscplot.c +++ b/oscplot.c @@ -4436,13 +4436,15 @@ static void plot_destroyed (GtkWidget *object, OscPlot *plot) static GdkPixbuf * window_get_screenshot_pixbuf(GtkWidget *window) { GdkWindow *gdk_w; + GtkAllocation allocation; gint width, height; gdk_w = gtk_widget_get_window(window); + gtk_widget_get_allocation(window, &allocation); width = gdk_window_get_width(gdk_w); height = gdk_window_get_height(gdk_w); - return gdk_pixbuf_get_from_window(gdk_w, 0, 0, width, height); + return gdk_pixbuf_get_from_window(gdk_w, allocation.x, allocation.y, width, height); } static void screenshot_saveas_png(OscPlot *plot) From c65ab555cd73c2daee9fb1421ec1df116898badb Mon Sep 17 00:00:00 2001 From: Michael Hennerich Date: Fri, 13 Oct 2023 13:04:16 +0200 Subject: [PATCH 3/4] oscplot: Fix save as csv/vsa/mat for devices with output channels not all channels are input or scan channels, so omit them. Signed-off-by: Michael Hennerich --- oscplot.c | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/oscplot.c b/oscplot.c index 1a7c5a0e..c246bbc1 100644 --- a/oscplot.c +++ b/oscplot.c @@ -4021,10 +4021,14 @@ static void saveas_device_changed_cb(GtkComboBoxText *box, OscPlot *plot) for (i = 0; i < channels->len; ++i) { struct iio_channel *chn = g_array_index(channels, struct iio_channel *, i); - const char *name = iio_channel_get_name(chn) ?: - iio_channel_get_id(chn); - ch_checkbtn = gtk_check_button_new_with_label(name); - gtk_box_pack_start(GTK_BOX(priv->saveas_channels_list), ch_checkbtn, FALSE, TRUE, 0); + + if (!iio_channel_is_output(chn) && iio_channel_is_scan_element(chn)) { + + const char *name = iio_channel_get_name(chn) ?: + iio_channel_get_id(chn); + ch_checkbtn = gtk_check_button_new_with_label(name); + gtk_box_pack_start(GTK_BOX(priv->saveas_channels_list), ch_checkbtn, FALSE, TRUE, 0); + } } g_array_free(channels, FALSE); gtk_widget_show_all(priv->saveas_channels_list); @@ -4525,7 +4529,7 @@ static void channel_selection_set_default(OscPlot *plot) g_free(device_name); } -static int * get_user_saveas_channel_selection(OscPlot *plot, unsigned int nb_channels) +static int * get_user_saveas_channel_selection(OscPlot *plot, unsigned int *nb_channels) { OscPlotPrivate *priv = plot->priv; GList *ch_checkbtns; @@ -4533,11 +4537,13 @@ static int * get_user_saveas_channel_selection(OscPlot *plot, unsigned int nb_ch GtkToggleButton *btn; int *mask; - /* Create masks for all channels */ - mask = malloc(sizeof(int) * nb_channels); - /* Get user channel selection from GUI widgets */ ch_checkbtns = gtk_container_get_children(GTK_CONTAINER(priv->saveas_channels_list)); + + /* Create masks for all channels */ + mask = malloc(sizeof(int) * g_list_length(ch_checkbtns)); + *nb_channels = g_list_length(ch_checkbtns); + for (node = ch_checkbtns; node; node = g_list_next(node)) { btn = (GtkToggleButton *)node->data; @@ -4624,10 +4630,9 @@ static void save_as(OscPlot *plot, const char *filename, int type) break; dev = iio_context_get_device(ctx, d); dev_info = iio_device_get_data(dev); - nb_channels = iio_device_get_channels_count(dev); /* Find which channel need to be saved */ - save_channels_mask = get_user_saveas_channel_selection(plot, nb_channels); + save_channels_mask = get_user_saveas_channel_selection(plot, &nb_channels); /* Make a VSA file header */ fprintf(fp, "InputZoom\tTRUE\n"); @@ -4681,10 +4686,9 @@ static void save_as(OscPlot *plot, const char *filename, int type) dev = iio_context_get_device(ctx, d); dev_info = iio_device_get_data(dev); - nb_channels = iio_device_get_channels_count(dev); /* Find which channel need to be saved */ - save_channels_mask = get_user_saveas_channel_selection(plot, nb_channels); + save_channels_mask = get_user_saveas_channel_selection(plot, &nb_channels); dev_sample_count = dev_info->sample_count; if (dev_info->channel_trigger_enabled) @@ -4743,12 +4747,11 @@ static void save_as(OscPlot *plot, const char *filename, int type) dev = iio_context_get_device(ctx, d); dev_info = iio_device_get_data(dev); - nb_channels = iio_device_get_channels_count(dev); dev_name = iio_device_get_name(dev) ?: iio_device_get_id(dev); /* Find which channel need to be saved */ - save_channels_mask = get_user_saveas_channel_selection(plot, nb_channels); + save_channels_mask = get_user_saveas_channel_selection(plot, &nb_channels); dev_sample_count = dev_info->sample_count; if (dev_info->channel_trigger_enabled) @@ -5270,15 +5273,20 @@ static int channel_find_by_name(struct iio_context *ctx, int device_index, return -1; dev = iio_context_get_device(ctx, device_index); + if (dev) nb_channels = iio_device_get_channels_count(dev); for (i = 0; i < nb_channels; i++) { struct iio_channel *chn = iio_device_get_channel(dev, i); - const char *id = iio_channel_get_name(chn) ?: - iio_channel_get_id(chn); - if (!strcmp(id, name)) - return i; + + if (!iio_channel_is_output(chn) && iio_channel_is_scan_element(chn)) { + + const char *id = iio_channel_get_name(chn) ?: + iio_channel_get_id(chn); + if (!strcmp(id, name)) + return i; + } } return -1; } From 938d5a0339d5adfd03e63d44277cdcadd297b3ad Mon Sep 17 00:00:00 2001 From: Cristina Suteu Date: Fri, 13 Oct 2023 15:10:51 +0300 Subject: [PATCH 4/4] oscplot: ensure channels dispalyed in save dialog are all inputs Signed-off-by: Cristina Suteu --- oscplot.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/oscplot.c b/oscplot.c index c246bbc1..b8813219 100644 --- a/oscplot.c +++ b/oscplot.c @@ -4504,7 +4504,7 @@ static void copy_channel_state_to_selection_channel(GtkTreeModel *model, for (node = ch_checkbtns; node; node = g_list_next(node)) { btn = (GtkToggleButton *)node->data; g_object_get(btn, "label", &btn_label, NULL); - if (!strcmp(ch_name, btn_label)) { + if (!strcmp(ch_name, btn_label) && !iio_channel_is_output(chn)) { gtk_toggle_button_set_active(btn, active_state); g_free(btn_label); break;