GDS-Render v1.2.1
lib-cell-renderer.c
Go to the documentation of this file.
1/*
2 * GDSII-Converter
3 * Copyright (C) 2018 Mario Hüttel <mario.huettel@gmx.net>
4 *
5 * This file is part of GDSII-Converter.
6 *
7 * GDSII-Converter is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 * GDSII-Converter is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GDSII-Converter. If not, see <http://www.gnu.org/licenses/>.
18 */
19
33
34G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT)
35
36enum {
41};
42
44{
45 (void)self;
46 /* Nothing to do */
47}
48
49static void lib_cell_renderer_constructed(GObject *obj)
50{
51 G_OBJECT_CLASS(lib_cell_renderer_parent_class)->constructed(obj);
52}
53
54static void convert_error_level_to_color(GdkRGBA *color, unsigned int error_level)
55{
56
57 /* Always use no transparency */
58 color->alpha = 1.0;
59
60 if (error_level & LIB_CELL_RENDERER_ERROR_ERR) {
61 /* Error set. Color cell red */
62 color->red = 1.0;
63 color->blue = 0.0;
64 color->green = 0.0;
65 } else if (error_level & LIB_CELL_RENDERER_ERROR_WARN) {
66 /* Only warning set; orange color */
67 color->red = 1.0;
68 color->blue = 0.0;
69 color->green = 0.6;
70 } else {
71 /* Everything okay; green color */
72 color->red = (double)61.0/(double)255.0;
73 color->green = (double)152.0/(double)255.0;
74 color->blue = 0.0;
75 }
76}
77
78static void lib_cell_renderer_set_property(GObject *object,
79 guint param_id,
80 const GValue *value,
81 GParamSpec *pspec)
82{
83 GValue val = G_VALUE_INIT;
84 GdkRGBA color;
85
86 switch (param_id) {
87 case PROP_LIB:
88 g_value_init(&val, G_TYPE_STRING);
89 g_value_set_string(&val, ((struct gds_library *)g_value_get_pointer(value))->name);
90 g_object_set_property(object, "text", &val);
91 g_value_unset(&val);
92 break;
93 case PROP_CELL:
94 g_value_init(&val, G_TYPE_STRING);
95 g_value_set_string(&val, ((struct gds_cell *)g_value_get_pointer(value))->name);
96 g_object_set_property(object, "text", &val);
97 g_value_unset(&val);
98 break;
100 /* Set cell color according to error level */
101 g_value_init(&val, GDK_TYPE_RGBA);
102 convert_error_level_to_color(&color, g_value_get_uint(value));
103 g_value_set_boxed(&val, &color);
104 g_object_set_property(object, "foreground-rgba", &val);
105 g_value_unset(&val);
106 break;
107 default:
108 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
109 break;
110 }
111}
112
113static void lib_cell_renderer_get_property(GObject *object,
114 guint param_id,
115 GValue *value,
116 GParamSpec *pspec)
117{
118 (void)value;
119
120 switch (param_id) {
121 default:
122 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
123 break;
124 }
125}
126
127static GParamSpec *properties[PROP_COUNT];
128
129void lib_cell_renderer_class_init(LibCellRendererClass *klass)
130{
131 GObjectClass *oclass = G_OBJECT_CLASS(klass);
132
133 oclass->constructed = lib_cell_renderer_constructed;
134 oclass->set_property = lib_cell_renderer_set_property;
135 oclass->get_property = lib_cell_renderer_get_property;
136
137 properties[PROP_LIB] = g_param_spec_pointer("gds-lib", "gds-lib",
138 "Library reference to be displayed",
139 G_PARAM_WRITABLE);
140 properties[PROP_CELL] = g_param_spec_pointer("gds-cell", "gds-cell",
141 "Cell reference to be displayed",
142 G_PARAM_WRITABLE);
143 properties[PROP_ERROR_LEVEL] = g_param_spec_uint("error-level", "error-level",
144 "Error level of this cell", 0, 255, 0, G_PARAM_WRITABLE);
145
146 g_object_class_install_properties(oclass, PROP_COUNT, properties);
147}
148
149GtkCellRenderer *lib_cell_renderer_new()
150{
151 return GTK_CELL_RENDERER(g_object_new(TYPE_LIB_CELL_RENDERER, NULL));
152}
153
Defines types and macros used by the GDS-Parser.
#define TYPE_LIB_CELL_RENDERER
static void lib_cell_renderer_set_property(GObject *object, guint param_id, const GValue *value, GParamSpec *pspec)
static GParamSpec * properties[PROP_COUNT]
static void convert_error_level_to_color(GdkRGBA *color, unsigned int error_level)
void lib_cell_renderer_init(LibCellRenderer *self)
GtkCellRenderer * lib_cell_renderer_new()
Create a new renderer for renderering gds_cell and gds_library elements.
#define LIB_CELL_RENDERER_ERROR_ERR
static void lib_cell_renderer_get_property(GObject *object, guint param_id, GValue *value, GParamSpec *pspec)
void lib_cell_renderer_class_init(LibCellRendererClass *klass)
static void lib_cell_renderer_constructed(GObject *obj)
#define LIB_CELL_RENDERER_ERROR_WARN
@ PROP_COUNT
Sentinel.
@ PROP_LIB
Library to display the name of.
@ PROP_ERROR_LEVEL
Error level of cell/library for coloring.
@ PROP_CELL
Cell to display the name of.
Header file for the LibCellRenderer GObject Class.
A Cell inside a gds_library.
Definition: gds-types.h:122
GDS Toplevel library.
Definition: gds-types.h:135