From 29f66951d1f7bf7616bdcaf6bc660658ca34d563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 22 May 2018 16:17:14 +0200 Subject: [PATCH] Completely restructudred code * Subfolders for different modules * LaTeX output module started * Convert button sensitivity impemented --- CMakeLists.txt | 12 ++-- gdsparse.c => gds-parser/gds-parser.c | 2 +- gds-types.h | 59 ------------------ glade/main.glade | 73 ++++++++++------------- gdsparse.h => latex-output/latex-output.c | 12 ++-- layer-selector.c | 54 ++++++++++------- layer-selector.h | 15 ++--- layer-widget/layer-element.c | 1 - main.c | 36 +++++++++-- tree-renderer/lib-cell-renderer.c | 2 +- tree-renderer/tree-store.c | 2 +- 11 files changed, 114 insertions(+), 154 deletions(-) rename gdsparse.c => gds-parser/gds-parser.c (99%) delete mode 100644 gds-types.h rename gdsparse.h => latex-output/latex-output.c (76%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f9dd2e3..5213015 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,20 +7,24 @@ project(gds-render) add_subdirectory(glade) -include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS} "layer-widget") +include_directories(${GLIB_INCLUDE_DIRS} ${GTK3_INCLUDE_DIRS}) link_directories(${GLIB_LINK_DIRS} ${GTK3_LINK_DIRS}) add_definitions(${GLIB2_CFLAGS_OTHER}) -aux_source_directory("layer-widget" SUB_SOURCES) +aux_source_directory("layer-widget" LAYER_SOURCES) aux_source_directory("tree-renderer" RENDERER_SOURCES) -set(SOURCE "main.c" "gdsparse.c" "layer-selector.c") +aux_source_directory("gds-parser" PARSER_SOURCES) +aux_source_directory("latex-output" LATEX_SOURCES) +set(SOURCE "main.c" "layer-selector.c") set(SOURCE ${SOURCE} - ${SUB_SOURCES} + ${LAYER_SOURCES} ${RENDERER_SOURCES} + ${PARSER_SOURCES} + ${LATEX_SOURCES} ) diff --git a/gdsparse.c b/gds-parser/gds-parser.c similarity index 99% rename from gdsparse.c rename to gds-parser/gds-parser.c index 488f398..db344db 100644 --- a/gdsparse.c +++ b/gds-parser/gds-parser.c @@ -27,7 +27,7 @@ */ -#include "gdsparse.h" +#include "gds-parser.h" #include #include #include diff --git a/gds-types.h b/gds-types.h deleted file mode 100644 index 999e26c..0000000 --- a/gds-types.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef __GDS_TYPES_H__ -#define __GDS_TYPES_H__ - -#include - -#define CELL_NAME_MAX (100) - -enum graphics_type {GRAPHIC_PATH = 0, GRAPHIC_POLYGON = 1}; - -struct gds_time_field { - uint16_t year; - uint16_t month; - uint16_t day; - uint16_t hour; - uint16_t minute; - uint16_t second; -}; - -struct gds_point { - int x; - int y; -}; - -struct gds_graphics { - enum graphics_type type; - GList *vertices; - unsigned int path_width; - int width_absolute; - int16_t layer; - uint16_t datatype; -}; - -struct gds_cell_instance { - char ref_name[CELL_NAME_MAX]; - struct gds_cell *cell_ref; - struct gds_point origin; - int flipped; - double angle; - double magnification; -}; - -struct gds_cell { - char name[CELL_NAME_MAX]; - struct gds_time_field mod_time; - struct gds_time_field access_time; - GList *child_cells; - GList *graphic_objs; -}; - -struct gds_library { - char name[CELL_NAME_MAX]; - struct gds_time_field mod_time; - struct gds_time_field access_time; - double unit_to_meters; - GList *cells; - GList *cell_names; -}; - -#endif /* __GDS_TYPES_H__ */ diff --git a/glade/main.glade b/glade/main.glade index 50fab57..83e25ee 100644 --- a/glade/main.glade +++ b/glade/main.glade @@ -3,6 +3,7 @@ + 250 True False @@ -57,6 +58,24 @@ 2 + + + gtk-convert + button-convert + True + False + True + True + True + True + + + + 3 + + @@ -64,15 +83,23 @@ True False - + True True - - + never + in + + + True + True + + + + - False + True True 0 @@ -81,6 +108,7 @@ True True + never in @@ -102,43 +130,6 @@ 1 - - - True - False - vertical - - - gtk-convert - button-convert - True - True - True - True - True - - - - False - True - 0 - - - - - - - - - - - False - True - 2 - - diff --git a/gdsparse.h b/latex-output/latex-output.c similarity index 76% rename from gdsparse.h rename to latex-output/latex-output.c index f5f571f..6768ff3 100644 --- a/gdsparse.h +++ b/latex-output/latex-output.c @@ -17,13 +17,9 @@ * along with GDSII-Converter. If not, see . */ -#ifndef __GDSPARSE_H__ -#define __GDSPARSE_H__ +#include "latex-output.h" -#include -#include "gds-types.h" +void render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file) +{ -int parse_gds_from_file(const char *filename, GList **library_array); -int clear_lib_list(GList **library_list); - -#endif /* __GDSPARSE_H__ */ +} diff --git a/layer-selector.c b/layer-selector.c index f9f3480..9b57dfa 100644 --- a/layer-selector.c +++ b/layer-selector.c @@ -18,7 +18,8 @@ */ #include "layer-selector.h" -#include "gdsparse.h" +#include "gds-parser/gds-parser.h" +#include "layer-widget/layer-element.h" #include #include #include @@ -27,33 +28,42 @@ static GList *layer_widgets = NULL; static GtkWidget *load_button; static GtkWidget *save_button; -static void layer_list_remove_element(struct layer_info *inf) -{ - if (inf) - free(inf); -} - -void get_layer_info(GList **info_list, GtkListBox *box) -{ - GList *local_list = NULL; - - /* Clear info Glist */ - if (*info_list != NULL) { - g_list_free_full(*info_list, (GDestroyNotify)layer_list_remove_element); - *info_list = NULL; - } - - - - *info_list = local_list; -} - static void delete_layer_widget(GtkWidget *widget) { gtk_widget_destroy(widget); } +/** + * @brief export_rendered_layer_info + * @return new list with all info elements needed to render cells + */ +GList *export_rendered_layer_info() +{ + GList *info_list = NULL; + LayerElement *le; + struct layer_info *linfo; + GList *widget_list; + + /* Iterate through widgets and add layers that shall be exported */ + for (widget_list = layer_widgets; widget_list != NULL; widget_list = widget_list->next) { + + le = LAYER_ELEMENT(widget_list->data); + + 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); + + /* Append to list */ + info_list = g_list_append(info_list, (gpointer)linfo); + } + } + + return info_list; +} + void clear_list_box_widgets(GtkListBox *box) { GList *list; diff --git a/layer-selector.h b/layer-selector.h index c2015cb..78fd8c7 100644 --- a/layer-selector.h +++ b/layer-selector.h @@ -22,21 +22,16 @@ #include #include -#include -struct layer_info { - int id; - /* This contains both: opacity and Color */ - GdkRGBA color; +struct layer_info +{ + int layer; + GdkRGBA color; }; void generate_layer_widgets(GtkListBox *listbox, GList *libs); -void clear_list_box_widgets(); - void setup_load_mapping_callback(GtkWidget *button, GtkWindow *main_window); void setup_save_mapping_callback(GtkWidget *button, GtkWindow *main_window); - -void get_layer_info(GList **info_list, GtkListBox *box); - +GList *export_rendered_layer_info(); #endif /* __LAYER_SELECTOR_H__ */ diff --git a/layer-widget/layer-element.c b/layer-widget/layer-element.c index d6aa310..a36a1bf 100644 --- a/layer-widget/layer-element.c +++ b/layer-widget/layer-element.c @@ -21,7 +21,6 @@ G_DEFINE_TYPE(LayerElement, layer_element, GTK_TYPE_BOX) - static void layer_element_dispose(GObject *obj) { /* destroy parent container. This destroys all widgets inside */ diff --git a/main.c b/main.c index e78e20b..48f33ff 100644 --- a/main.c +++ b/main.c @@ -18,12 +18,12 @@ */ #include -#include "gdsparse.h" +#include "gds-parser/gds-parser.h" #include -#include +#include "layer-widget/layer-element.h" #include "layer-selector.h" -#include "tree-renderer/lib-cell-renderer.h" #include "tree-renderer/tree-store.h" +#include "latex-output/latex-output.h" struct open_button_data { GtkWindow *main_window; @@ -32,6 +32,11 @@ struct open_button_data { GtkListBox *layer_box; }; +struct convert_button_data { + GList *layer_info; + GtkTreeView *tree_view; +}; + gboolean on_window_close(gpointer window, gpointer user) { gtk_widget_destroy(GTK_WIDGET(window)); @@ -156,9 +161,24 @@ end_destroy: static void on_convert_clicked(gpointer button, gpointer user) { + struct convert_button_data *data = (struct convert_button_data *)user; printf("convert\n"); } +/* 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); + } +} int main(int argc, char **argv) { @@ -166,7 +186,8 @@ int main(int argc, char **argv) GList *gds_libs = NULL; GtkTreeView *cell_tree; GtkTreeStore *cell_store; - GtkWidget *widget_generic; + GtkWidget *conv_button; + GtkWidget *layer; GtkWidget *listbox; @@ -191,8 +212,8 @@ int main(int argc, char **argv) /* Connect Convert button */ - widget_generic = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button")); - g_signal_connect(widget_generic, "clicked", G_CALLBACK(on_convert_clicked), layer); + conv_button = GTK_WIDGET(gtk_builder_get_object(main_builder, "convert-button")); + g_signal_connect(conv_button, "clicked", G_CALLBACK(on_convert_clicked), layer); listbox = GTK_WIDGET(gtk_builder_get_object(main_builder, "layer-list")); open_data.layer_box = GTK_LIST_BOX(listbox); @@ -203,6 +224,9 @@ int main(int argc, char **argv) setup_save_mapping_callback(GTK_WIDGET(gtk_builder_get_object(main_builder, "button-save-mapping")), open_data.main_window); + /* 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); gtk_main(); diff --git a/tree-renderer/lib-cell-renderer.c b/tree-renderer/lib-cell-renderer.c index 6e6da8b..192210b 100644 --- a/tree-renderer/lib-cell-renderer.c +++ b/tree-renderer/lib-cell-renderer.c @@ -18,7 +18,7 @@ */ #include "lib-cell-renderer.h" -#include "../gds-types.h" +#include "../gds-parser/gds-types.h" G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT) diff --git a/tree-renderer/tree-store.c b/tree-renderer/tree-store.c index d729ce0..d111055 100644 --- a/tree-renderer/tree-store.c +++ b/tree-renderer/tree-store.c @@ -1,6 +1,6 @@ #include "tree-store.h" #include "lib-cell-renderer.h" -#include "../gds-types.h" +#include "../gds-parser/gds-types.h" static gboolean tree_sel_func(GtkTreeSelection *selection, GtkTreeModel *model,