2018-05-16 16:27:38 +02:00
|
|
|
/*
|
|
|
|
* GDSII-Converter
|
|
|
|
* Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*
|
|
|
|
* This file is part of GDSII-Converter.
|
|
|
|
*
|
|
|
|
* GDSII-Converter is free software: you can redistribute it and/or modify
|
2018-05-16 16:29:34 +02:00
|
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
|
|
* published by the Free Software Foundation.
|
2018-05-16 16:27:38 +02:00
|
|
|
*
|
|
|
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
2018-12-10 23:37:00 +01:00
|
|
|
* @file layer-selector.c
|
2018-07-24 18:47:29 +02:00
|
|
|
* @brief Implementation of the layer selector
|
|
|
|
* @author Mario Hüttel <mario.huettel@gmx.net>
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup MainApplication
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
#include "layer-selector.h"
|
2018-05-22 16:17:14 +02:00
|
|
|
#include "gds-parser/gds-parser.h"
|
2018-07-19 15:11:18 +02:00
|
|
|
#include "widgets/layer-element.h"
|
2018-05-17 21:46:14 +02:00
|
|
|
#include <glib.h>
|
|
|
|
#include <string.h>
|
2018-05-18 22:47:39 +02:00
|
|
|
#include <stdio.h>
|
2018-06-04 11:37:36 +02:00
|
|
|
#include <stdlib.h>
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
static GtkWidget *global_load_button;
|
|
|
|
static GtkWidget *global_save_button;
|
|
|
|
static GtkListBox *global_list_box;
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-22 18:45:23 +02:00
|
|
|
void delete_layer_info_struct(struct layer_info *info)
|
|
|
|
{
|
|
|
|
if (info)
|
|
|
|
free(info);
|
|
|
|
}
|
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
/**
|
|
|
|
* @brief export_rendered_layer_info
|
|
|
|
* @return new list with all info elements needed to render cells
|
|
|
|
*/
|
|
|
|
GList *export_rendered_layer_info()
|
2018-05-16 16:20:09 +02:00
|
|
|
{
|
2018-05-22 16:17:14 +02:00
|
|
|
GList *info_list = NULL;
|
|
|
|
LayerElement *le;
|
|
|
|
struct layer_info *linfo;
|
2018-05-23 01:03:16 +02:00
|
|
|
GList *row_list;
|
|
|
|
GList *temp;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
row_list = gtk_container_get_children(GTK_CONTAINER(global_list_box));
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
/* Iterate through widgets and add layers that shall be exported */
|
2018-05-23 01:03:16 +02:00
|
|
|
for (i = 0, temp = row_list; temp != NULL; temp = temp->next, i++) {
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
le = LAYER_ELEMENT(temp->data);
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
if (layer_element_get_export(le) == TRUE) {
|
|
|
|
/* Allocate new info and fill with info */
|
|
|
|
linfo = (struct layer_info *)malloc(sizeof(struct layer_info));
|
|
|
|
layer_element_get_color(le, &linfo->color);
|
|
|
|
linfo->layer = layer_element_get_layer(le);
|
2018-05-23 01:03:16 +02:00
|
|
|
linfo->stacked_position = i;
|
2018-05-31 00:06:00 +02:00
|
|
|
linfo->name = (char *)layer_element_get_name(le);
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
/* Append to list */
|
|
|
|
info_list = g_list_append(info_list, (gpointer)linfo);
|
|
|
|
}
|
|
|
|
}
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
return info_list;
|
2018-05-16 16:20:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void clear_list_box_widgets(GtkListBox *box)
|
|
|
|
{
|
|
|
|
GList *list;
|
2018-05-23 01:03:16 +02:00
|
|
|
GList *temp;
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
list = gtk_container_get_children(GTK_CONTAINER(box));
|
2018-05-23 01:03:16 +02:00
|
|
|
for (temp = list; temp != NULL; temp = temp->next) {
|
|
|
|
gtk_container_remove(GTK_CONTAINER(box), GTK_WIDGET(temp->data));
|
2018-05-16 16:20:09 +02:00
|
|
|
}
|
2018-05-17 21:46:14 +02:00
|
|
|
/* Widgets are already destroyed when removed from box because they are only referenced inside the container */
|
2018-05-23 01:03:16 +02:00
|
|
|
|
|
|
|
g_list_free(list);
|
2018-05-17 21:46:14 +02:00
|
|
|
|
|
|
|
/* Deactivate buttons */
|
2018-05-23 01:03:16 +02:00
|
|
|
gtk_widget_set_sensitive(global_load_button, FALSE);
|
|
|
|
gtk_widget_set_sensitive(global_save_button, FALSE);
|
2018-05-16 16:20:09 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Check if specific layer number is present in list box
|
|
|
|
* @param layer Layer nu,ber
|
|
|
|
* @return TRUE if present
|
|
|
|
*/
|
2018-05-16 16:20:09 +02:00
|
|
|
static gboolean check_if_layer_widget_exists(int layer) {
|
|
|
|
GList *list;
|
2018-05-23 01:03:16 +02:00
|
|
|
GList *temp;
|
2018-05-16 16:20:09 +02:00
|
|
|
LayerElement *widget;
|
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
list = gtk_container_get_children(GTK_CONTAINER(global_list_box));
|
|
|
|
|
|
|
|
for (temp = list; temp != NULL; temp = temp->next) {
|
|
|
|
widget = LAYER_ELEMENT(temp->data);
|
2018-05-16 16:20:09 +02:00
|
|
|
if (layer_element_get_layer(widget) == layer) {
|
|
|
|
ret = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 01:03:16 +02:00
|
|
|
|
|
|
|
g_list_free(list);
|
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Analyze \p cell and append used layers to list box
|
|
|
|
* @param listbox listbox to add layer
|
|
|
|
* @param cell Cell to analyze
|
|
|
|
*/
|
2018-05-16 16:20:09 +02:00
|
|
|
static void analyze_cell_layers(GtkListBox *listbox, struct gds_cell *cell)
|
|
|
|
{
|
|
|
|
GList *graphics;
|
|
|
|
struct gds_graphics *gfx;
|
|
|
|
int layer;
|
|
|
|
GtkWidget *le;
|
|
|
|
|
|
|
|
for (graphics = cell->graphic_objs; graphics != NULL; graphics = graphics->next) {
|
|
|
|
gfx = (struct gds_graphics *)graphics->data;
|
|
|
|
layer = (int)gfx->layer;
|
|
|
|
if (check_if_layer_widget_exists(layer) == FALSE) {
|
|
|
|
le = layer_element_new();
|
|
|
|
layer_element_set_layer(LAYER_ELEMENT(le), layer);
|
|
|
|
gtk_list_box_insert(listbox, le, -1);
|
|
|
|
gtk_widget_show(le);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief sort_func Sort callback for list box
|
|
|
|
* @param row1
|
|
|
|
* @param row2
|
|
|
|
* @param unused
|
2019-03-12 19:26:31 +01:00
|
|
|
* @note Do not use this function. This is an internal callback
|
|
|
|
* @return See sort function documentation of GTK+
|
2018-07-24 18:47:29 +02:00
|
|
|
*/
|
|
|
|
static gint sort_func(GtkListBoxRow *row1, GtkListBoxRow *row2, gpointer unused)
|
2018-05-16 16:20:09 +02:00
|
|
|
{
|
|
|
|
LayerElement *le1, *le2;
|
|
|
|
gint ret;
|
2019-03-12 19:26:31 +01:00
|
|
|
enum layer_selector_sort_algo default_sort = LAYER_SELECTOR_SORT_DOWN;
|
|
|
|
enum layer_selector_sort_algo *algo = (enum layer_selector_sort_algo *)unused;
|
|
|
|
|
|
|
|
/* Assume downward sorting */
|
|
|
|
if (!algo)
|
|
|
|
algo = &default_sort;
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
le1 = LAYER_ELEMENT(row1);
|
|
|
|
le2 = LAYER_ELEMENT(row2);
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2019-03-12 19:26:31 +01:00
|
|
|
/* Determine sort fow downward sort */
|
2018-05-16 16:20:09 +02:00
|
|
|
ret = layer_element_get_layer(le1) - layer_element_get_layer(le2);
|
|
|
|
|
2019-03-12 19:26:31 +01:00
|
|
|
/* Change order if upward sort is requested */
|
|
|
|
ret *= (*algo == LAYER_SELECTOR_SORT_DOWN ? 1 : -1);
|
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void generate_layer_widgets(GtkListBox *listbox, GList *libs)
|
|
|
|
{
|
|
|
|
GList *cell_list = NULL;
|
|
|
|
struct gds_library *lib;
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
global_list_box = listbox;
|
|
|
|
|
2018-05-22 18:45:23 +02:00
|
|
|
clear_list_box_widgets(listbox);
|
2018-05-16 16:20:09 +02:00
|
|
|
gtk_list_box_set_sort_func(listbox, sort_func, NULL, NULL);
|
|
|
|
|
|
|
|
for (; libs != NULL; libs = libs->next) {
|
|
|
|
lib = (struct gds_library *)libs->data;
|
|
|
|
for (cell_list = lib->cells; cell_list != NULL; cell_list = cell_list->next) {
|
|
|
|
analyze_cell_layers(listbox, (struct gds_cell *)cell_list->data);
|
|
|
|
} /* For Cell List */
|
|
|
|
} /* For libs */
|
|
|
|
|
|
|
|
/* Force sort */
|
|
|
|
gtk_list_box_invalidate_sort(listbox);
|
2018-05-17 21:46:14 +02:00
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
/* Disable sort, so user can sort layers */
|
|
|
|
gtk_list_box_set_sort_func(listbox, NULL, NULL, NULL);
|
|
|
|
|
2018-05-17 21:46:14 +02:00
|
|
|
/* Activate Buttons */
|
2018-05-23 01:03:16 +02:00
|
|
|
gtk_widget_set_sensitive(global_load_button, TRUE);
|
|
|
|
gtk_widget_set_sensitive(global_save_button, TRUE);
|
2018-05-17 21:46:14 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Find LayerElement in list with specified layer number
|
|
|
|
* @param el_list List with elements of type LayerElement
|
|
|
|
* @param layer Layer number
|
|
|
|
* @return Found LayerElement. If nothing is found, NULL.
|
|
|
|
*/
|
2018-05-23 01:03:16 +02:00
|
|
|
static LayerElement *find_layer_element_in_list(GList *el_list, int layer)
|
2018-05-18 22:47:39 +02:00
|
|
|
{
|
2018-05-23 01:03:16 +02:00
|
|
|
LayerElement *ret = NULL;
|
|
|
|
for (; el_list != NULL; el_list = el_list->next) {
|
|
|
|
if (layer_element_get_layer(LAYER_ELEMENT(el_list->data)) == layer) {
|
|
|
|
ret = LAYER_ELEMENT(el_list->data);
|
2018-05-18 22:47:39 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-05-23 01:03:16 +02:00
|
|
|
return ret;
|
2018-05-18 22:47:39 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Load file and apply layer definitions to listbox
|
|
|
|
* @param file_name CSV Layer Mapping File
|
|
|
|
*/
|
2018-05-18 22:47:39 +02:00
|
|
|
static void load_layer_mapping_from_file(gchar *file_name)
|
|
|
|
{
|
|
|
|
GFile *file;
|
|
|
|
GFileInputStream *stream;
|
|
|
|
GDataInputStream *dstream;
|
|
|
|
LayerElement *le;
|
|
|
|
char *name;
|
|
|
|
gboolean export;
|
|
|
|
int layer;
|
|
|
|
GdkRGBA color;
|
|
|
|
int result;
|
2018-05-23 01:03:16 +02:00
|
|
|
GList *rows;
|
|
|
|
GList *temp;
|
2018-05-18 22:47:39 +02:00
|
|
|
|
|
|
|
file = g_file_new_for_path(file_name);
|
|
|
|
stream = g_file_read(file, NULL, NULL);
|
|
|
|
|
|
|
|
if (!stream)
|
|
|
|
goto destroy_file;
|
|
|
|
|
|
|
|
dstream = g_data_input_stream_new(G_INPUT_STREAM(stream));
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
rows = gtk_container_get_children(GTK_CONTAINER(global_list_box));
|
|
|
|
|
|
|
|
/* Reference and remove all rows from box */
|
|
|
|
for (temp = rows; temp != NULL; temp = temp->next) {
|
|
|
|
le = LAYER_ELEMENT(temp->data);
|
|
|
|
/* Referencing protets the widget from being deleted when removed */
|
|
|
|
g_object_ref(G_OBJECT(le));
|
|
|
|
gtk_container_remove(GTK_CONTAINER(global_list_box), GTK_WIDGET(le));
|
|
|
|
}
|
|
|
|
|
|
|
|
while((result = load_csv_line(dstream, &export, &name, &layer, &color)) >= 0) {
|
2018-05-18 22:47:39 +02:00
|
|
|
/* skip broken line */
|
|
|
|
if (result == 1)
|
|
|
|
continue;
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
/* Add rows in the same order as in file */
|
2018-06-05 22:51:50 +02:00
|
|
|
if ((le = find_layer_element_in_list(rows, layer))) {
|
2018-05-23 01:03:16 +02:00
|
|
|
gtk_list_box_insert(global_list_box, GTK_WIDGET(le), -1);
|
|
|
|
|
2018-05-18 22:47:39 +02:00
|
|
|
layer_element_set_color(le, &color);
|
|
|
|
layer_element_set_export(le, export);
|
2018-05-23 01:03:16 +02:00
|
|
|
layer_element_set_name(le, name);
|
2018-05-23 13:17:10 +02:00
|
|
|
g_free(name);
|
2018-05-23 01:03:16 +02:00
|
|
|
|
|
|
|
/* Dereference and remove from list */
|
|
|
|
g_object_unref(G_OBJECT(le));
|
|
|
|
rows = g_list_remove(rows, le);
|
2018-05-18 22:47:39 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
/* Add remaining elements */
|
|
|
|
for (temp = rows; temp != NULL; temp = temp->next) {
|
|
|
|
le = LAYER_ELEMENT(temp->data);
|
|
|
|
/* Referencing protets the widget from being deleted when removed */
|
|
|
|
gtk_list_box_insert(global_list_box, GTK_WIDGET(le), -1);
|
|
|
|
g_object_unref(G_OBJECT(le));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete list */
|
|
|
|
g_list_free(rows);
|
|
|
|
|
2018-05-18 22:47:39 +02:00
|
|
|
/* read line */
|
|
|
|
g_object_unref(dstream);
|
|
|
|
g_object_unref(stream);
|
|
|
|
destroy_file:
|
|
|
|
g_object_unref(file);
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for Load Mapping Button
|
|
|
|
* @param button
|
|
|
|
* @param user_data
|
|
|
|
*/
|
2018-05-17 21:46:14 +02:00
|
|
|
static void load_mapping_clicked(GtkWidget *button, gpointer user_data)
|
|
|
|
{
|
2018-05-18 22:47:39 +02:00
|
|
|
GtkWidget *dialog;
|
|
|
|
gint res;
|
|
|
|
gchar *file_name;
|
|
|
|
|
|
|
|
dialog = gtk_file_chooser_dialog_new("Load Mapping File", GTK_WINDOW(user_data), GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
"Cancel", GTK_RESPONSE_CANCEL, "Load Mapping", GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
if (res == GTK_RESPONSE_ACCEPT) {
|
|
|
|
file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
|
|
|
load_layer_mapping_from_file(file_name);
|
|
|
|
g_free(file_name);
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(dialog);
|
2018-05-17 21:46:14 +02:00
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Create Line for LayerMapping file with supplied information
|
|
|
|
* @param layer_element information
|
|
|
|
* @param line_buffer buffer to write to
|
|
|
|
* @param max_len Maximum length that cna be used in \p line_buffer
|
|
|
|
*/
|
2018-05-17 21:46:14 +02:00
|
|
|
static void create_csv_line(LayerElement *layer_element, char *line_buffer, size_t max_len)
|
|
|
|
{
|
2019-02-03 22:44:03 +01:00
|
|
|
int i;
|
2018-05-17 21:46:14 +02:00
|
|
|
GString *string;
|
|
|
|
gboolean export;
|
|
|
|
const gchar *name;
|
|
|
|
int layer;
|
|
|
|
GdkRGBA color;
|
|
|
|
|
|
|
|
string = g_string_new_len(NULL, max_len-1);
|
|
|
|
|
|
|
|
/* Extract values */
|
|
|
|
export = layer_element_get_export(layer_element);
|
|
|
|
name = (const gchar*)layer_element_get_name(layer_element);
|
|
|
|
layer = layer_element_get_layer(layer_element);
|
|
|
|
layer_element_get_color(layer_element, &color);
|
|
|
|
|
|
|
|
/* print values to line */
|
2019-02-03 22:50:34 +01:00
|
|
|
g_string_printf(string, "%d:%lf:%lf:%lf:%lf:%d:%s\n",
|
2018-05-23 01:03:16 +02:00
|
|
|
layer, color.red, color.green,
|
2018-05-18 22:47:39 +02:00
|
|
|
color.blue, color.alpha, (export == TRUE ? 1 : 0), name);
|
2019-02-03 22:44:03 +01:00
|
|
|
/* Fix broken locale settings */
|
2019-02-03 22:47:34 +01:00
|
|
|
for (i = 0; string->str[i]; i++) {
|
|
|
|
if (string->str[i] == ',')
|
|
|
|
string->str[i] = '.';
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:44:03 +01:00
|
|
|
for (i = 0; string->str[i]; i++) {
|
|
|
|
if (string->str[i] == ':')
|
|
|
|
string->str[i] = ',';
|
|
|
|
}
|
2018-05-17 21:46:14 +02:00
|
|
|
|
|
|
|
if (string->len > (max_len-1)) {
|
|
|
|
printf("Layer Definition too long. Please shorten Layer Name!!\n");
|
|
|
|
line_buffer[0] = 0x0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* copy max_len bytes of string */
|
|
|
|
strncpy(line_buffer, (char *)string->str, max_len-1);
|
|
|
|
line_buffer[max_len-1] = 0;
|
|
|
|
|
|
|
|
/* Completely remove string */
|
|
|
|
g_string_free(string, TRUE);
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Save layer mapping of whole list box into file
|
|
|
|
* @param file_name layer mapping file
|
|
|
|
* @param list_box listbox
|
|
|
|
*/
|
2018-05-23 01:03:16 +02:00
|
|
|
static void save_layer_mapping_data(const gchar *file_name, GtkListBox *list_box)
|
2018-05-17 21:46:14 +02:00
|
|
|
{
|
|
|
|
FILE *file;
|
|
|
|
char workbuff[512];
|
|
|
|
GList *le_list;
|
2018-05-23 01:03:16 +02:00
|
|
|
GList *temp;
|
2018-05-17 21:46:14 +02:00
|
|
|
|
|
|
|
/* Overwrite existing file */
|
|
|
|
file = fopen((const char *)file_name, "w");
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
le_list = gtk_container_get_children(GTK_CONTAINER(list_box));
|
|
|
|
|
|
|
|
/* File format is CSV: <Layer>,<target_pos>,<R>,<G>,<B>,<Alpha>,<Export?>,<Name> */
|
|
|
|
for (temp = le_list; temp != NULL; temp = temp->next) {
|
2018-05-17 21:46:14 +02:00
|
|
|
/* To be sure it is a valid string */
|
|
|
|
workbuff[0] = 0;
|
2018-05-23 01:03:16 +02:00
|
|
|
create_csv_line(LAYER_ELEMENT(temp->data), workbuff, sizeof(workbuff));
|
2018-05-17 21:46:14 +02:00
|
|
|
fwrite(workbuff, sizeof(char), strlen(workbuff), file);
|
|
|
|
}
|
|
|
|
|
2018-05-23 01:03:16 +02:00
|
|
|
g_list_free(le_list);
|
|
|
|
|
2018-05-17 21:46:14 +02:00
|
|
|
/* Save File */
|
|
|
|
fflush(file);
|
|
|
|
fclose(file);
|
|
|
|
}
|
|
|
|
|
2018-07-24 18:47:29 +02:00
|
|
|
/**
|
|
|
|
* @brief Callback for Save Layer Mapping Button
|
|
|
|
* @param button
|
|
|
|
* @param user_data
|
|
|
|
*/
|
2018-05-17 21:46:14 +02:00
|
|
|
static void save_mapping_clicked(GtkWidget *button, gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkWidget *dialog;
|
|
|
|
gint res;
|
|
|
|
gchar *file_name;
|
|
|
|
|
|
|
|
dialog = gtk_file_chooser_dialog_new("Save Mapping File", GTK_WINDOW(user_data), GTK_FILE_CHOOSER_ACTION_SAVE,
|
2018-05-18 22:47:39 +02:00
|
|
|
"Cancel", GTK_RESPONSE_CANCEL, "Save Mapping", GTK_RESPONSE_ACCEPT, NULL);
|
2018-07-28 10:01:02 +02:00
|
|
|
gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
|
|
|
|
|
2018-05-17 21:46:14 +02:00
|
|
|
res = gtk_dialog_run(GTK_DIALOG(dialog));
|
|
|
|
if (res == GTK_RESPONSE_ACCEPT) {
|
|
|
|
file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
|
2018-05-23 01:03:16 +02:00
|
|
|
save_layer_mapping_data(file_name, global_list_box);
|
2018-05-17 21:46:14 +02:00
|
|
|
g_free(file_name);
|
|
|
|
}
|
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_load_mapping_callback(GtkWidget *button, GtkWindow *main_window)
|
|
|
|
{
|
|
|
|
g_object_ref(G_OBJECT(button));
|
2018-05-23 01:03:16 +02:00
|
|
|
global_load_button = button;
|
2018-05-17 21:46:14 +02:00
|
|
|
g_signal_connect(button, "clicked", G_CALLBACK(load_mapping_clicked), main_window);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setup_save_mapping_callback(GtkWidget *button, GtkWindow *main_window)
|
|
|
|
{
|
|
|
|
g_object_ref(G_OBJECT(button));
|
2018-05-23 01:03:16 +02:00
|
|
|
global_save_button = button;
|
2018-05-17 21:46:14 +02:00
|
|
|
g_signal_connect(button, "clicked", G_CALLBACK(save_mapping_clicked), main_window);
|
2018-05-16 16:20:09 +02:00
|
|
|
}
|
2018-07-24 18:47:29 +02:00
|
|
|
|
|
|
|
/** @} */
|