Implemented open file dialog

This commit is contained in:
Mario Hüttel 2018-05-10 00:14:00 +02:00
parent 34086e2458
commit e245c772f1
3 changed files with 333 additions and 281 deletions

View File

@ -1,3 +1,22 @@
/*
* 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
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License.
*
* 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 Foobar. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* What's missing? - A lot:
* Support for Boxes
@ -312,11 +331,9 @@ int parse_gds_from_file(const char *filename, GList **library_list)
struct gds_cell *current_cell = NULL;
struct gds_graphics *current_graphics = NULL;
struct gds_cell_instance *current_s_reference = NULL;
int x, y;
////////////
GList *lib_list;
GList *lib_ptr;
GList *cell_ptr;
GList *cell_ref_ptr;
lib_list = *library_list;
@ -329,8 +346,6 @@ int parse_gds_from_file(const char *filename, GList **library_list)
/* Record parser */
while (run == 1) {
switch (state) {
case PARSING_LENGTH:
rec_type = INVALID;
read = fread(workbuff, sizeof(char), 2, gds_file);
if (read != 2 && (current_cell != NULL ||
@ -363,9 +378,7 @@ int parse_gds_from_file(const char *filename, GList **library_list)
break;
}
rec_data_length -= 4;
state = PARSING_TYPE;
break;
case PARSING_TYPE:
read = fread(workbuff, sizeof(char), 2, gds_file);
if (read != 2) {
run = -2;
@ -507,11 +520,12 @@ int parse_gds_from_file(const char *filename, GList **library_list)
default:
//GDS_WARN("Record: %04x, len: %u", (unsigned int)rec_type, (unsigned int)rec_data_length);
break;
}
break;
} /* switch(rec_type) */
case PARSING_DAT:
/* No Data -> No Processing, go back to top */
if (!rec_data_length) continue;
read = fread(workbuff, sizeof(char), rec_data_length, gds_file);
state = PARSING_LENGTH;
@ -520,8 +534,6 @@ int parse_gds_from_file(const char *filename, GList **library_list)
run = -5;
break;
}
/* No Data -> No Processing */
if (!read) break;
switch (rec_type) {
case LIBNAME:
@ -535,12 +547,15 @@ int parse_gds_from_file(const char *filename, GList **library_list)
/* Get origin of reference */
current_s_reference->origin.x = gds_convert_signed_int(workbuff);
current_s_reference->origin.y = gds_convert_signed_int(&workbuff[4]);
printf("\t\tSet origin to: %d/%d\n", current_s_reference->origin.x,
current_s_reference->origin.y);
} else if (current_graphics) {
for (i = 0; i < read/8; i++) {
// printf("coords: %d/%d", gds_convert_signed_int(&workbuff[i*8]), gds_convert_signed_int(&workbuff[i*8+4]));
current_graphics->vertices = append_vertex(current_graphics->vertices,
gds_convert_signed_int(&workbuff[i*8]),
gds_convert_signed_int(&workbuff[i*8]));
x = gds_convert_signed_int(&workbuff[i*8]);
y = gds_convert_signed_int(&workbuff[i*8]);
current_graphics->vertices =
append_vertex(current_graphics->vertices, x, y);
printf("\t\tSet coordinate: %d/%d\n", x, y);
}
}
@ -594,10 +609,8 @@ int parse_gds_from_file(const char *filename, GList **library_list)
break;
}
break; /* PARSING_DAT */
}
}
} /* while(run == 1) */
fclose(gds_file);

View File

@ -2,7 +2,7 @@
<!-- Generated with glade 3.22.1 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<object class="GtkWindow">
<object class="GtkWindow" id="main-window">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="delete-event" handler="on_window_close" swapped="no"/>

47
main.c
View File

@ -10,6 +10,7 @@ STORE_COLUMN
struct open_button_data {
GtkWindow *main_window;
GList **list_ptr;
GtkTreeStore *cell_store;
};
@ -36,11 +37,46 @@ void on_load_gds(gpointer button, gpointer user)
struct gds_cell *gds_c;
struct open_button_data *ptr = (struct open_button_data *)user;
GtkTreeStore *store = ptr->cell_store;
GtkWidget *open_dialog;
GtkFileChooser *file_chooser;
GtkFileFilter *filter;
GtkStyleContext *button_style;
gint dialog_result;
int gds_result;
char *filename;
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);
/* Clear Display */
gtk_tree_store_clear(store);
/* Delete parsed GDS data */
clear_lib_list(ptr->list_ptr);
parse_gds_from_file("/home/mari/Desktop/test.gds", ptr->list_ptr);
/* 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;
@ -53,7 +89,10 @@ void on_load_gds(gpointer button, gpointer user)
gtk_tree_store_set (store, &celliter, CELL, gds_c->name, -1);
}
}
}
end_destroy:
gtk_widget_destroy(open_dialog);
}
void on_convert_clicked(gpointer button, gpointer user)
@ -66,7 +105,6 @@ static GtkTreeStore * setup_cell_selector(GtkTreeView* view)
GtkTreeStore *cell_store;
GtkCellRenderer *render;
GtkCellRenderer *render2;
GtkTreeViewColumn *column;
cell_store = gtk_tree_store_new(STORE_COLUMN, G_TYPE_STRING, G_TYPE_STRING);
@ -75,7 +113,7 @@ static GtkTreeStore * setup_cell_selector(GtkTreeView* view)
render = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes("Library", render, "text", LIBRARY, NULL);
gtk_tree_view_append_column(view, column);
//g_object_unref(column);
column = gtk_tree_view_column_new_with_attributes("Cell", render, "text", CELL, NULL);
gtk_tree_view_append_column(view, column);
@ -103,6 +141,7 @@ int main(int argc, char **argv)
open_data.cell_store = cell_store;
open_data.list_ptr = &gds_libs;
open_data.main_window = GTK_WINDOW(gtk_builder_get_object(main_builder, "main-window"));
g_signal_connect(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-load-gds")),
"clicked", G_CALLBACK(on_load_gds), (gpointer)&open_data);