Custom Library/Cell Renderer for tree view

This allows direct storing of library/cell structures instead of only names
This commit is contained in:
Mario Hüttel 2018-05-22 00:00:19 +02:00
parent 46cc20e878
commit 35d10a5a24
8 changed files with 229 additions and 67 deletions

View File

@ -13,12 +13,14 @@ add_definitions(${GLIB2_CFLAGS_OTHER})
aux_source_directory("layer-widget" SUB_SOURCES) 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 "main.c" "gdsparse.c" "layer-selector.c")
set(SOURCE set(SOURCE
${SOURCE} ${SOURCE}
${SUB_SOURCES} ${SUB_SOURCES}
${RENDERER_SOURCES}
) )

59
gds-types.h Normal file
View File

@ -0,0 +1,59 @@
#ifndef __GDS_TYPES_H__
#define __GDS_TYPES_H__
#include <stdint.h>
#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__ */

View File

@ -20,62 +20,8 @@
#ifndef __GDSPARSE_H__ #ifndef __GDSPARSE_H__
#define __GDSPARSE_H__ #define __GDSPARSE_H__
#include <stdint.h>
#include <glib.h> #include <glib.h>
#include "gds-types.h"
#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;
};
int parse_gds_from_file(const char *filename, GList **library_array); int parse_gds_from_file(const char *filename, GList **library_array);
int clear_lib_list(GList **library_list); int clear_lib_list(GList **library_list);

View File

@ -28,10 +28,16 @@ static void layer_element_dispose(GObject *obj)
G_OBJECT_CLASS(layer_element_parent_class)->dispose(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) static void layer_element_class_init(LayerElementClass *klass)
{ {
GObjectClass *oclass = G_OBJECT_CLASS(klass); GObjectClass *oclass = G_OBJECT_CLASS(klass);
oclass->dispose = layer_element_dispose; oclass->dispose = layer_element_dispose;
oclass->constructed = layer_element_constructed;
} }
static void layer_element_init(LayerElement *self) static void layer_element_init(LayerElement *self)

View File

@ -25,7 +25,7 @@
#define LAYER_ELEMENT(obj) G_TYPE_CHECK_INSTANCE_CAST(obj, layer_element_get_type(), LayerElement) #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 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 { typedef struct _LayerElementPriv {
GtkEntry *name; GtkEntry *name;

25
main.c
View File

@ -22,6 +22,7 @@
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <layer-element.h> #include <layer-element.h>
#include "layer-selector.h" #include "layer-selector.h"
#include "tree-renderer/lib-cell-renderer.h"
enum cell_store_columns { 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); acc_date = generate_string_from_date(&gds_lib->access_time);
gtk_tree_store_set (store, &libiter, gtk_tree_store_set (store, &libiter,
LIBRARY, gds_lib->name, LIBRARY, gds_lib,
MODDATE, mod_date->str, MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, ACCESSDATE, acc_date->str,
-1); -1);
@ -141,7 +142,7 @@ void on_load_gds(gpointer button, gpointer user)
acc_date = generate_string_from_date(&gds_c->access_time); acc_date = generate_string_from_date(&gds_c->access_time);
gtk_tree_store_set (store, &celliter, gtk_tree_store_set (store, &celliter,
CELL, gds_c->name, CELL, gds_c,
MODDATE, mod_date->str, MODDATE, mod_date->str,
ACCESSDATE, acc_date->str, ACCESSDATE, acc_date->str,
-1); -1);
@ -171,19 +172,21 @@ static GtkTreeStore * setup_cell_selector(GtkTreeView* view)
{ {
GtkTreeStore *cell_store; GtkTreeStore *cell_store;
GtkCellRenderer *render; GtkCellRenderer *render_dates;
GtkCellRenderer *render_cell; GtkCellRenderer *render_cell;
GtkCellRenderer *render_lib;
GtkTreeViewColumn *column; GtkTreeViewColumn *column;
GdkRGBA cell_text_color; GdkRGBA cell_text_color;
GValue val = G_VALUE_INIT; 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)); gtk_tree_view_set_model(view, GTK_TREE_MODEL(cell_store));
render = gtk_cell_renderer_text_new(); render_dates = gtk_cell_renderer_text_new();
render_cell = 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.alpha = 1;
cell_text_color.red = (double)61.0/(double)255.0; cell_text_color.red = (double)61.0/(double)255.0;
cell_text_color.green = (double)152.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); gtk_tree_view_append_column(view, column);
/* Cell color: #3D9801 */ /* 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); 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); 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); gtk_tree_view_append_column(view, column);
return cell_store; return cell_store;

View File

@ -0,0 +1,99 @@
/*
* 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 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 <http://www.gnu.org/licenses/>.
*/
#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));
}

View File

@ -0,0 +1,47 @@
/*
* 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 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 <http://www.gnu.org/licenses/>.
*/
#ifndef __LIB_CELL_RENDERER_H__
#define __LIB_CELL_RENDERER_H__
#include <gtk/gtk.h>
#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__ */