From 35d10a5a24bfb2b5c6c2016680b8f0351992b6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Tue, 22 May 2018 00:00:19 +0200 Subject: [PATCH] Custom Library/Cell Renderer for tree view This allows direct storing of library/cell structures instead of only names --- CMakeLists.txt | 2 + gds-types.h | 59 ++++++++++++++++++ gdsparse.h | 56 +---------------- layer-widget/layer-element.c | 6 ++ layer-widget/layer-element.h | 2 +- main.c | 25 ++++---- tree-renderer/lib-cell-renderer.c | 99 +++++++++++++++++++++++++++++++ tree-renderer/lib-cell-renderer.h | 47 +++++++++++++++ 8 files changed, 229 insertions(+), 67 deletions(-) create mode 100644 gds-types.h create mode 100644 tree-renderer/lib-cell-renderer.c create mode 100644 tree-renderer/lib-cell-renderer.h diff --git a/CMakeLists.txt b/CMakeLists.txt index b153ce3..f9dd2e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,12 +13,14 @@ add_definitions(${GLIB2_CFLAGS_OTHER}) aux_source_directory("layer-widget" SUB_SOURCES) +aux_source_directory("tree-renderer" RENDERER_SOURCES) set(SOURCE "main.c" "gdsparse.c" "layer-selector.c") set(SOURCE ${SOURCE} ${SUB_SOURCES} + ${RENDERER_SOURCES} ) diff --git a/gds-types.h b/gds-types.h new file mode 100644 index 0000000..999e26c --- /dev/null +++ b/gds-types.h @@ -0,0 +1,59 @@ +#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/gdsparse.h b/gdsparse.h index 97f3f32..f5f571f 100644 --- a/gdsparse.h +++ b/gdsparse.h @@ -20,62 +20,8 @@ #ifndef __GDSPARSE_H__ #define __GDSPARSE_H__ -#include #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; -}; - +#include "gds-types.h" int parse_gds_from_file(const char *filename, GList **library_array); int clear_lib_list(GList **library_list); diff --git a/layer-widget/layer-element.c b/layer-widget/layer-element.c index 9e530ba..a6ecf69 100644 --- a/layer-widget/layer-element.c +++ b/layer-widget/layer-element.c @@ -28,10 +28,16 @@ static void layer_element_dispose(GObject *obj) G_OBJECT_CLASS(layer_element_parent_class)->dispose(obj); } +static void layer_element_constructed(GObject *obj) +{ + G_OBJECT_CLASS(layer_element_parent_class)->constructed(obj); +} + static void layer_element_class_init(LayerElementClass *klass) { GObjectClass *oclass = G_OBJECT_CLASS(klass); oclass->dispose = layer_element_dispose; + oclass->constructed = layer_element_constructed; } static void layer_element_init(LayerElement *self) diff --git a/layer-widget/layer-element.h b/layer-widget/layer-element.h index 8c3e288..7ab5ca9 100644 --- a/layer-widget/layer-element.h +++ b/layer-widget/layer-element.h @@ -25,7 +25,7 @@ #define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement) #define LAYER_ELEMENT_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, layer_element_get_type(), LayerElementClass) -#define IS_LAYE_RELEMENT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) +#define IS_LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) typedef struct _LayerElementPriv { GtkEntry *name; diff --git a/main.c b/main.c index b723bd8..75f6c26 100644 --- a/main.c +++ b/main.c @@ -22,6 +22,7 @@ #include #include #include "layer-selector.h" +#include "tree-renderer/lib-cell-renderer.h" enum cell_store_columns { @@ -122,7 +123,7 @@ void on_load_gds(gpointer button, gpointer user) acc_date = generate_string_from_date(&gds_lib->access_time); gtk_tree_store_set (store, &libiter, - LIBRARY, gds_lib->name, + LIBRARY, gds_lib, MODDATE, mod_date->str, ACCESSDATE, acc_date->str, -1); @@ -141,7 +142,7 @@ void on_load_gds(gpointer button, gpointer user) acc_date = generate_string_from_date(&gds_c->access_time); gtk_tree_store_set (store, &celliter, - CELL, gds_c->name, + CELL, gds_c, MODDATE, mod_date->str, ACCESSDATE, acc_date->str, -1); @@ -171,19 +172,21 @@ static GtkTreeStore * setup_cell_selector(GtkTreeView* view) { GtkTreeStore *cell_store; - GtkCellRenderer *render; + GtkCellRenderer *render_dates; GtkCellRenderer *render_cell; + GtkCellRenderer *render_lib; GtkTreeViewColumn *column; GdkRGBA cell_text_color; GValue val = G_VALUE_INIT; - cell_store = gtk_tree_store_new(STORE_COLUMN_COUNT, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + cell_store = gtk_tree_store_new(STORE_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_STRING, G_TYPE_STRING); gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store)); - render = gtk_cell_renderer_text_new(); - render_cell = gtk_cell_renderer_text_new(); + render_dates = gtk_cell_renderer_text_new(); + render_cell = lib_cell_renderer_new(); + render_lib = lib_cell_renderer_new(); - /* Set foreground color */ + /* Set foreground color for cell column */ cell_text_color.alpha = 1; cell_text_color.red = (double)61.0/(double)255.0; cell_text_color.green = (double)152.0/(double)255.0; @@ -202,17 +205,17 @@ static GtkTreeStore * setup_cell_selector(GtkTreeView* view) - column = gtk_tree_view_column_new_with_attributes("Library", render, "text", LIBRARY, NULL); + column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", LIBRARY, NULL); gtk_tree_view_append_column(view, column); /* Cell color: #3D9801 */ - column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "text", CELL, NULL); + column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL, NULL); gtk_tree_view_append_column(view, column); - column = gtk_tree_view_column_new_with_attributes("Mod. Date", render, "text", MODDATE, NULL); + column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", MODDATE, NULL); gtk_tree_view_append_column(view, column); - column = gtk_tree_view_column_new_with_attributes("Acc. Date", render, "text", ACCESSDATE, NULL); + column = gtk_tree_view_column_new_with_attributes("Acc. Date", render_dates, "text", ACCESSDATE, NULL); gtk_tree_view_append_column(view, column); return cell_store; diff --git a/tree-renderer/lib-cell-renderer.c b/tree-renderer/lib-cell-renderer.c new file mode 100644 index 0000000..6e6da8b --- /dev/null +++ b/tree-renderer/lib-cell-renderer.c @@ -0,0 +1,99 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * 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 version 2 as + * published by the Free Software Foundation. + * + * 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 . + */ + +#include "lib-cell-renderer.h" +#include "../gds-types.h" + +G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT) + +enum { + PROP_LIB = 1, + PROP_CELL, + PROP_COUNT +}; + +void lib_cell_renderer_init(LibCellRenderer *self) +{ + /* Nothing to do */ +} + +static void lib_cell_renderer_constructed(GObject *obj) +{ + G_OBJECT_CLASS(lib_cell_renderer_parent_class)->constructed(obj); +} + +static void lib_cell_renderer_set_property(GObject *object, + guint param_id, + const GValue *value, + GParamSpec *pspec) +{ + GValue val = G_VALUE_INIT; + + g_value_init(&val, G_TYPE_STRING); + + switch (param_id) { + case PROP_LIB: + g_value_set_string(&val, ((struct gds_library *)g_value_get_pointer(value))->name); + g_object_set_property(object, "text", &val); + break; + case PROP_CELL: + g_value_set_string(&val, ((struct gds_cell *)g_value_get_pointer(value))->name); + g_object_set_property(object, "text", &val); + break; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); + break; + } +} + +static void lib_cell_renderer_get_property(GObject *object, + guint param_id, + GValue *value, + GParamSpec *pspec) +{ + switch (param_id) { + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); + break; + } +} + +static GParamSpec *properties [PROP_COUNT]; + +void lib_cell_renderer_class_init(LibCellRendererClass *klass) +{ + GObjectClass *oclass = G_OBJECT_CLASS(klass); + oclass->constructed = lib_cell_renderer_constructed; + oclass->set_property = lib_cell_renderer_set_property; + oclass->get_property = lib_cell_renderer_get_property; + + properties[PROP_LIB] = g_param_spec_pointer("gds-lib", "gds-lib", + "Library reference to be displayed", + G_PARAM_WRITABLE); + properties[PROP_CELL] = g_param_spec_pointer("gds-cell", "gds-cell", + "Cell reference to be displayed", + G_PARAM_WRITABLE); + + g_object_class_install_properties(oclass, PROP_COUNT, properties); +} + +GtkCellRenderer *lib_cell_renderer_new() +{ + return GTK_CELL_RENDERER(g_object_new(TYPE_LIB_CELL_RENDERER, NULL)); +} diff --git a/tree-renderer/lib-cell-renderer.h b/tree-renderer/lib-cell-renderer.h new file mode 100644 index 0000000..eea28ab --- /dev/null +++ b/tree-renderer/lib-cell-renderer.h @@ -0,0 +1,47 @@ +/* + * GDSII-Converter + * Copyright (C) 2018 Mario Hüttel + * + * 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 version 2 as + * published by the Free Software Foundation. + * + * 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 . + */ + +#ifndef __LIB_CELL_RENDERER_H__ +#define __LIB_CELL_RENDERER_H__ + + +#include + +#define LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, lib_cell_renderer_get_type(), LibCellRenderer) +#define LIB_CELL_RENDERER_CLASS(klass) G_TYPE_CHECK_CLASS_CAST(klass, lib_cell_renderer_get_type(), LibCellRendererClass) +#define IS_LIB_CELL_RENDERER(obj) G_TYPE_CHECK_INSTANCE_TYPE(obj, layer_element_get_type()) +#define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) + +typedef struct _LibCellRenderer { + /* Inheritance */ + GtkCellRendererText super; + /* Custom Elements */ +} LibCellRenderer; + +typedef struct _LibCellRendererClass { + GtkCellRendererTextClass parent; +} LibCellRendererClass; + + +GType lib_cell_renderer_get_type(void); +GtkCellRenderer *lib_cell_renderer_new(void); + + + +#endif /* __LIB_CELL_RENDERER_H__ */