2018-05-10 01:43:14 +02:00
|
|
|
/*
|
2018-05-15 22:54:10 +02:00
|
|
|
* GDSII-Converter
|
2018-05-10 01:43:14 +02:00
|
|
|
* 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-10 01:43:14 +02:00
|
|
|
*
|
2018-05-15 22:54:10 +02:00
|
|
|
* GDSII-Converter is distributed in the hope that it will be useful,
|
2018-05-10 01:43:14 +02:00
|
|
|
* 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-05-07 13:27:50 +02:00
|
|
|
#include <stdio.h>
|
2018-05-22 16:17:14 +02:00
|
|
|
#include "gds-parser/gds-parser.h"
|
2018-05-08 15:00:37 +02:00
|
|
|
#include <gtk/gtk.h>
|
2018-05-22 16:17:14 +02:00
|
|
|
#include "layer-widget/layer-element.h"
|
2018-05-16 16:20:09 +02:00
|
|
|
#include "layer-selector.h"
|
2018-05-22 12:59:28 +02:00
|
|
|
#include "tree-renderer/tree-store.h"
|
2018-05-22 16:17:14 +02:00
|
|
|
#include "latex-output/latex-output.h"
|
2018-05-08 16:50:30 +02:00
|
|
|
|
2018-05-08 16:02:44 +02:00
|
|
|
struct open_button_data {
|
2018-05-15 16:57:08 +02:00
|
|
|
GtkWindow *main_window;
|
|
|
|
GList **list_ptr;
|
|
|
|
GtkTreeStore *cell_store;
|
2018-05-16 16:20:09 +02:00
|
|
|
GtkListBox *layer_box;
|
2018-05-08 16:02:44 +02:00
|
|
|
};
|
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
struct convert_button_data {
|
|
|
|
GtkTreeView *tree_view;
|
2018-05-22 18:45:23 +02:00
|
|
|
GtkWindow *main_window;
|
2018-05-22 16:17:14 +02:00
|
|
|
};
|
|
|
|
|
2018-05-08 15:00:37 +02:00
|
|
|
gboolean on_window_close(gpointer window, gpointer user)
|
|
|
|
{
|
|
|
|
gtk_widget_destroy(GTK_WIDGET(window));
|
|
|
|
gtk_main_quit();
|
|
|
|
return TRUE;
|
|
|
|
}
|
2018-05-07 15:57:47 +02:00
|
|
|
|
2018-05-19 20:26:33 +02:00
|
|
|
static GString *generate_string_from_date(struct gds_time_field *date)
|
|
|
|
{
|
|
|
|
GString *str;
|
|
|
|
|
|
|
|
str = g_string_new_len(NULL, 50);
|
|
|
|
g_string_printf(str, "%02u.%02u.%u - %02u:%02u",
|
|
|
|
(unsigned int)date->day,
|
|
|
|
(unsigned int)date->month,
|
|
|
|
(unsigned int)date->year,
|
|
|
|
(unsigned int)date->hour,
|
|
|
|
(unsigned int)date->minute);
|
|
|
|
return str;
|
|
|
|
}
|
2018-05-08 16:02:44 +02:00
|
|
|
|
2018-05-08 15:00:37 +02:00
|
|
|
void on_load_gds(gpointer button, gpointer user)
|
2018-05-07 13:27:50 +02:00
|
|
|
{
|
2018-05-08 16:02:44 +02:00
|
|
|
GList *cell;
|
|
|
|
GtkTreeIter libiter;
|
|
|
|
GtkTreeIter celliter;
|
|
|
|
GList *lib;
|
|
|
|
struct gds_library *gds_lib;
|
|
|
|
struct gds_cell *gds_c;
|
|
|
|
struct open_button_data *ptr = (struct open_button_data *)user;
|
|
|
|
GtkTreeStore *store = ptr->cell_store;
|
2018-05-10 00:14:00 +02:00
|
|
|
GtkWidget *open_dialog;
|
|
|
|
GtkFileChooser *file_chooser;
|
|
|
|
GtkFileFilter *filter;
|
|
|
|
GtkStyleContext *button_style;
|
|
|
|
gint dialog_result;
|
|
|
|
int gds_result;
|
|
|
|
char *filename;
|
2018-05-19 20:26:33 +02:00
|
|
|
GString *mod_date;
|
|
|
|
GString *acc_date;
|
2018-05-10 00:14:00 +02:00
|
|
|
|
|
|
|
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window, GTK_FILE_CHOOSER_ACTION_OPEN,
|
|
|
|
"Cancel", GTK_RESPONSE_CANCEL, "Open GDSII", GTK_RESPONSE_ACCEPT, NULL);
|
|
|
|
file_chooser = GTK_FILE_CHOOSER(open_dialog);
|
|
|
|
/* Add GDS II Filter */
|
|
|
|
filter = gtk_file_filter_new();
|
|
|
|
gtk_file_filter_add_pattern(filter, "*.gds");
|
|
|
|
gtk_file_filter_set_name(filter, "GDSII-Files");
|
|
|
|
gtk_file_chooser_add_filter(file_chooser, filter);
|
|
|
|
|
|
|
|
dialog_result = gtk_dialog_run(GTK_DIALOG(open_dialog));
|
|
|
|
|
|
|
|
if (dialog_result == GTK_RESPONSE_ACCEPT) {
|
|
|
|
|
|
|
|
/* Get File name */
|
|
|
|
filename = gtk_file_chooser_get_filename(file_chooser);
|
|
|
|
|
|
|
|
gtk_tree_store_clear(store);
|
2018-05-16 10:32:00 +02:00
|
|
|
clear_lib_list(ptr->list_ptr);
|
2018-05-10 00:14:00 +02:00
|
|
|
|
|
|
|
/* Parse new GDSII file */
|
|
|
|
gds_result = parse_gds_from_file(filename, ptr->list_ptr);
|
|
|
|
|
|
|
|
/* Delete file name afterwards */
|
|
|
|
g_free(filename);
|
|
|
|
if (gds_result)
|
|
|
|
goto end_destroy;
|
|
|
|
|
|
|
|
/* remove suggested action from Open button */
|
|
|
|
button_style = gtk_widget_get_style_context(GTK_WIDGET(button));
|
|
|
|
gtk_style_context_remove_class(button_style, "suggested-action");
|
|
|
|
|
|
|
|
for (lib = *(ptr->list_ptr); lib != NULL; lib = lib->next) {
|
|
|
|
gds_lib = (struct gds_library *)lib->data;
|
|
|
|
/* Create top level iter */
|
|
|
|
gtk_tree_store_append (store, &libiter, NULL);
|
2018-05-19 20:26:33 +02:00
|
|
|
|
|
|
|
/* Convert dates to String */
|
|
|
|
mod_date = generate_string_from_date(&gds_lib->mod_time);
|
|
|
|
acc_date = generate_string_from_date(&gds_lib->access_time);
|
|
|
|
|
|
|
|
gtk_tree_store_set (store, &libiter,
|
2018-05-22 12:59:28 +02:00
|
|
|
CELL_SEL_LIBRARY, gds_lib,
|
|
|
|
CELL_SEL_MODDATE, mod_date->str,
|
|
|
|
CELL_SEL_ACCESSDATE, acc_date->str,
|
2018-05-19 20:26:33 +02:00
|
|
|
-1);
|
|
|
|
|
|
|
|
/* Delete GStrings including string data. */
|
|
|
|
/* Cell store copies String type data items */
|
|
|
|
g_string_free(mod_date, TRUE);
|
|
|
|
g_string_free(acc_date, TRUE);
|
|
|
|
|
2018-05-10 00:14:00 +02:00
|
|
|
for (cell = gds_lib->cells; cell != NULL; cell = cell->next) {
|
|
|
|
gds_c = (struct gds_cell *)cell->data;
|
|
|
|
gtk_tree_store_append (store, &celliter, &libiter);
|
2018-05-19 20:26:33 +02:00
|
|
|
|
|
|
|
/* Convert dates to String */
|
|
|
|
mod_date = generate_string_from_date(&gds_c->mod_time);
|
|
|
|
acc_date = generate_string_from_date(&gds_c->access_time);
|
|
|
|
|
|
|
|
gtk_tree_store_set (store, &celliter,
|
2018-05-22 12:59:28 +02:00
|
|
|
CELL_SEL_CELL, gds_c,
|
|
|
|
CELL_SEL_MODDATE, mod_date->str,
|
|
|
|
CELL_SEL_ACCESSDATE, acc_date->str,
|
2018-05-19 20:26:33 +02:00
|
|
|
-1);
|
|
|
|
|
|
|
|
/* Delete GStrings including string data. */
|
|
|
|
/* Cell store copies String type data items */
|
|
|
|
g_string_free(mod_date, TRUE);
|
|
|
|
g_string_free(acc_date, TRUE);
|
2018-05-10 00:14:00 +02:00
|
|
|
}
|
2018-05-08 16:02:44 +02:00
|
|
|
}
|
2018-05-16 16:20:09 +02:00
|
|
|
|
|
|
|
/* Create Layers in Layer Box */
|
|
|
|
generate_layer_widgets(ptr->layer_box, *(ptr->list_ptr));
|
2018-05-08 16:02:44 +02:00
|
|
|
}
|
2018-05-08 15:00:37 +02:00
|
|
|
|
2018-05-10 00:14:00 +02:00
|
|
|
end_destroy:
|
2018-05-17 21:46:14 +02:00
|
|
|
/* Destroy dialog and filter */
|
2018-05-10 00:14:00 +02:00
|
|
|
gtk_widget_destroy(open_dialog);
|
2018-05-08 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 12:59:28 +02:00
|
|
|
static void on_convert_clicked(gpointer button, gpointer user)
|
2018-05-08 15:00:37 +02:00
|
|
|
{
|
2018-05-22 16:17:14 +02:00
|
|
|
struct convert_button_data *data = (struct convert_button_data *)user;
|
2018-05-22 18:45:23 +02:00
|
|
|
GtkTreeSelection *selection;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
GtkTreeModel *model;
|
|
|
|
GList *layer_list;
|
|
|
|
struct gds_cell *cell_to_render;
|
|
|
|
FILE *tex_file;
|
|
|
|
GtkWidget *dialog;
|
|
|
|
gint res;
|
|
|
|
char *file_name;
|
|
|
|
|
|
|
|
/* Get selected cell */
|
|
|
|
selection = gtk_tree_view_get_selection(data->tree_view);
|
|
|
|
if (gtk_tree_selection_get_selected(selection, &model, &iter) == FALSE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
gtk_tree_model_get(model, &iter, CELL_SEL_CELL, &cell_to_render, -1);
|
|
|
|
|
|
|
|
if (!cell_to_render)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Get layers that are rendered */
|
|
|
|
layer_list = export_rendered_layer_info();
|
|
|
|
|
|
|
|
/* save file dialog */
|
|
|
|
dialog = gtk_file_chooser_dialog_new("Save TeX File", GTK_WINDOW(data->main_window), GTK_FILE_CHOOSER_ACTION_SAVE,
|
|
|
|
"Cancel", GTK_RESPONSE_CANCEL, "Save", 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));
|
|
|
|
tex_file = fopen(file_name, "w");
|
|
|
|
g_free(file_name);
|
2018-05-24 00:15:39 +02:00
|
|
|
gtk_widget_destroy(dialog);
|
|
|
|
render_cell_to_code(cell_to_render, layer_list, tex_file);
|
|
|
|
fclose(tex_file);
|
2018-05-24 00:36:55 +02:00
|
|
|
} else {
|
|
|
|
gtk_widget_destroy(dialog);
|
2018-05-22 18:45:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full(layer_list, (GDestroyNotify)delete_layer_info_struct);
|
2018-05-08 15:00:37 +02:00
|
|
|
}
|
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
/* This function activates/deactivates the convert button depending on whether
|
|
|
|
* a cell is selected for conversion or not */
|
|
|
|
static void cell_selection_changed(GtkTreeSelection *sel, GtkWidget *convert_button)
|
|
|
|
{
|
|
|
|
GtkTreeModel *model = NULL;
|
|
|
|
GtkTreeIter iter;
|
|
|
|
|
|
|
|
if (gtk_tree_selection_get_selected(sel, &model, &iter)) {
|
|
|
|
/* Node selected. Show button */
|
|
|
|
gtk_widget_set_sensitive(convert_button, TRUE);
|
|
|
|
} else {
|
|
|
|
gtk_widget_set_sensitive(convert_button, FALSE);
|
|
|
|
}
|
|
|
|
}
|
2018-05-08 16:02:44 +02:00
|
|
|
|
2018-05-08 15:00:37 +02:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
GtkBuilder *main_builder;
|
|
|
|
GList *gds_libs = NULL;
|
2018-05-08 16:02:44 +02:00
|
|
|
GtkTreeView *cell_tree;
|
|
|
|
GtkTreeStore *cell_store;
|
2018-05-22 16:17:14 +02:00
|
|
|
GtkWidget *conv_button;
|
2018-05-16 16:20:09 +02:00
|
|
|
GtkWidget *listbox;
|
2018-05-15 16:57:08 +02:00
|
|
|
|
2018-05-08 16:02:44 +02:00
|
|
|
struct open_button_data open_data;
|
2018-05-22 18:45:23 +02:00
|
|
|
struct convert_button_data conv_data;
|
2018-05-08 15:00:37 +02:00
|
|
|
|
|
|
|
gtk_init(&argc, &argv);
|
|
|
|
|
2018-05-18 18:47:19 +02:00
|
|
|
main_builder = gtk_builder_new_from_resource("/main.glade");
|
2018-05-08 15:00:37 +02:00
|
|
|
gtk_builder_connect_signals(main_builder, NULL);
|
|
|
|
|
2018-05-08 16:02:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
cell_tree = (GtkTreeView *)gtk_builder_get_object(main_builder, "cell-tree");
|
|
|
|
cell_store = setup_cell_selector(cell_tree);
|
|
|
|
|
|
|
|
|
|
|
|
open_data.cell_store = cell_store;
|
|
|
|
open_data.list_ptr = &gds_libs;
|
2018-05-10 00:14:00 +02:00
|
|
|
open_data.main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window"));
|
2018-05-08 15:00:37 +02:00
|
|
|
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds")),
|
2018-05-08 16:02:44 +02:00
|
|
|
"clicked", G_CALLBACK(on_load_gds), (gpointer)&open_data);
|
2018-06-04 11:41:35 +02:00
|
|
|
|
|
|
|
/* Connect delete-event */
|
|
|
|
g_signal_connect(GTK_WIDGET(open_data.main_window), "delete-event", G_CALLBACK(on_window_close), NULL);
|
2018-05-15 22:51:22 +02:00
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
|
2018-05-15 22:51:22 +02:00
|
|
|
/* Connect Convert button */
|
2018-05-22 18:45:23 +02:00
|
|
|
conv_data.tree_view = cell_tree;
|
|
|
|
conv_data.main_window = open_data.main_window;
|
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
conv_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button"));
|
2018-05-22 18:45:23 +02:00
|
|
|
g_signal_connect(conv_button, "clicked", G_CALLBACK(on_convert_clicked), &conv_data);
|
2018-05-07 15:17:29 +02:00
|
|
|
|
2018-05-16 16:20:09 +02:00
|
|
|
listbox = GTK_WIDGET(gtk_builder_get_object(main_builder, "layer-list"));
|
|
|
|
open_data.layer_box = GTK_LIST_BOX(listbox);
|
2018-05-15 16:57:08 +02:00
|
|
|
|
2018-05-17 21:46:14 +02:00
|
|
|
/* Set buttons fpr layer mapping GUI */
|
|
|
|
setup_load_mapping_callback(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-mapping")),
|
|
|
|
open_data.main_window);
|
|
|
|
setup_save_mapping_callback(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")),
|
|
|
|
open_data.main_window);
|
|
|
|
|
2018-05-22 16:17:14 +02:00
|
|
|
/* Callback for selection change of cell selector */
|
|
|
|
g_signal_connect(G_OBJECT(gtk_tree_view_get_selection(cell_tree)), "changed",
|
|
|
|
G_CALLBACK(cell_selection_changed), conv_button);
|
2018-05-17 21:46:14 +02:00
|
|
|
|
2018-05-08 15:00:37 +02:00
|
|
|
gtk_main();
|
2018-05-07 13:27:50 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|