Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix save feature #458

Merged
merged 4 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion glade/oscplot.glade
Original file line number Diff line number Diff line change
Expand Up @@ -1716,7 +1716,7 @@
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
Expand Down
50 changes: 30 additions & 20 deletions oscplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -4436,13 +4440,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)
Expand Down Expand Up @@ -4498,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;
Expand All @@ -4523,19 +4529,21 @@ 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;
GList *node;
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;

Expand Down Expand Up @@ -4622,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");
Expand Down Expand Up @@ -4679,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)
Expand Down Expand Up @@ -4741,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)
Expand Down Expand Up @@ -5268,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;
}
Expand Down