Implement error level indicator for cells

This commit is contained in:
Mario Hüttel 2019-03-05 20:50:54 +01:00
parent 976bdd9854
commit e9b67fe1bc
5 changed files with 45 additions and 13 deletions

View File

@ -114,7 +114,6 @@ static void on_load_gds(gpointer button, gpointer user)
char *filename; char *filename;
GString *mod_date; GString *mod_date;
GString *acc_date; GString *acc_date;
GdkRGBA cell_text_color;
open_dialog = gtk_file_chooser_dialog_new("Open GDSII File", ptr->main_window, GTK_FILE_CHOOSER_ACTION_OPEN, 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); "Cancel", GTK_RESPONSE_CANCEL, "Open GDSII", GTK_RESPONSE_ACCEPT, NULL);
@ -175,11 +174,6 @@ static void on_load_gds(gpointer button, gpointer user)
mod_date = generate_string_from_date(&gds_c->mod_time); mod_date = generate_string_from_date(&gds_c->mod_time);
acc_date = generate_string_from_date(&gds_c->access_time); acc_date = generate_string_from_date(&gds_c->access_time);
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;
cell_text_color.blue = 0.0;
/* Add cell to tree store model /* Add cell to tree store model
* CELL_SEL_CELL_COLOR will always be green, * CELL_SEL_CELL_COLOR will always be green,
* because no cell cehcker is implemented, yet. * because no cell cehcker is implemented, yet.
@ -188,7 +182,7 @@ static void on_load_gds(gpointer button, gpointer user)
CELL_SEL_CELL, gds_c, CELL_SEL_CELL, gds_c,
CELL_SEL_MODDATE, mod_date->str, CELL_SEL_MODDATE, mod_date->str,
CELL_SEL_ACCESSDATE, acc_date->str, CELL_SEL_ACCESSDATE, acc_date->str,
CELL_SEL_CELL_COLOR, &cell_text_color, // TODO: implement cell checker CELL_SEL_CELL_ERROR_STATE, 0, // TODO: implement cell checker
-1); -1);
/* Delete GStrings including string data. */ /* Delete GStrings including string data. */

View File

@ -25,6 +25,7 @@ G_DEFINE_TYPE(LibCellRenderer, lib_cell_renderer, GTK_TYPE_CELL_RENDERER_TEXT)
enum { enum {
PROP_LIB = 1, PROP_LIB = 1,
PROP_CELL, PROP_CELL,
PROP_ERROR_LEVEL,
PROP_COUNT PROP_COUNT
}; };
@ -38,24 +39,56 @@ static void lib_cell_renderer_constructed(GObject *obj)
G_OBJECT_CLASS(lib_cell_renderer_parent_class)->constructed(obj); G_OBJECT_CLASS(lib_cell_renderer_parent_class)->constructed(obj);
} }
static void convert_error_level_to_color(GdkRGBA *color, unsigned int error_level)
{
/* Always use no transparency */
color->alpha = 1.0;
if (error_level & LIB_CELL_RENDERER_ERROR_ERR) {
/* Error set. Color cell red */
color->red = 1.0;
color->blue = 0.0;
color->green = 0.0;
} else if (error_level & LIB_CELL_RENDERER_ERROR_WARN) {
/* Only warning set; orange color */
color->red = 0.6;
color->blue = 0.0;
color->green = 0.4;
} else {
/* Everything okay; green color */
color->red = (double)61.0/(double)255.0;
color->green = (double)152.0/(double)255.0;
color->blue = 0.0;
}
}
static void lib_cell_renderer_set_property(GObject *object, static void lib_cell_renderer_set_property(GObject *object,
guint param_id, guint param_id,
const GValue *value, const GValue *value,
GParamSpec *pspec) GParamSpec *pspec)
{ {
GValue val = G_VALUE_INIT; GValue val = G_VALUE_INIT;
GdkRGBA color;
g_value_init(&val, G_TYPE_STRING);
switch (param_id) { switch (param_id) {
case PROP_LIB: case PROP_LIB:
g_value_init(&val, G_TYPE_STRING);
g_value_set_string(&val, ((struct gds_library *)g_value_get_pointer(value))->name); g_value_set_string(&val, ((struct gds_library *)g_value_get_pointer(value))->name);
g_object_set_property(object, "text", &val); g_object_set_property(object, "text", &val);
break; break;
case PROP_CELL: case PROP_CELL:
g_value_init(&val, G_TYPE_STRING);
g_value_set_string(&val, ((struct gds_cell *)g_value_get_pointer(value))->name); g_value_set_string(&val, ((struct gds_cell *)g_value_get_pointer(value))->name);
g_object_set_property(object, "text", &val); g_object_set_property(object, "text", &val);
break; break;
case PROP_ERROR_LEVEL:
/* Set cell color according to error level */
g_value_init(&val, GDK_TYPE_RGBA);
convert_error_level_to_color(&color, g_value_get_uint(value));
g_value_set_boxed(&val, &color);
g_object_set_property(object, "foreground-rgba", &val);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID(object, param_id, pspec);
break; break;
@ -89,6 +122,8 @@ void lib_cell_renderer_class_init(LibCellRendererClass *klass)
properties[PROP_CELL] = g_param_spec_pointer("gds-cell", "gds-cell", properties[PROP_CELL] = g_param_spec_pointer("gds-cell", "gds-cell",
"Cell reference to be displayed", "Cell reference to be displayed",
G_PARAM_WRITABLE); G_PARAM_WRITABLE);
properties[PROP_ERROR_LEVEL] = g_param_spec_uint("error-level", "error-level",
"Error level of this cell", 0, 255, 0, G_PARAM_WRITABLE);
g_object_class_install_properties(oclass, PROP_COUNT, properties); g_object_class_install_properties(oclass, PROP_COUNT, properties);
} }

View File

@ -27,6 +27,9 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText) G_DECLARE_FINAL_TYPE(LibCellRenderer, lib_cell_renderer, LIB_CELL, RENDERER, GtkCellRendererText)
#define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type()) #define TYPE_LIB_CELL_RENDERER (lib_cell_renderer_get_type())
#define LIB_CELL_RENDERER_ERROR_WARN (1U<<0)
#define LIB_CELL_RENDERER_ERROR_ERR (1U<<1)
typedef struct _LibCellRenderer { typedef struct _LibCellRenderer {
/* Inheritance */ /* Inheritance */
GtkCellRendererText super; GtkCellRendererText super;

View File

@ -127,7 +127,7 @@ struct tree_stores *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entr
stores.base_tree_view = view; stores.base_tree_view = view;
stores.search_entry = search_entry; stores.search_entry = search_entry;
stores.base_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, GDK_TYPE_RGBA, G_TYPE_STRING, G_TYPE_STRING); stores.base_store = gtk_tree_store_new(CELL_SEL_COLUMN_COUNT, G_TYPE_POINTER, G_TYPE_POINTER, G_TYPE_UINT, G_TYPE_STRING, G_TYPE_STRING);
/* Searching */ /* Searching */
if (search_entry) { if (search_entry) {
@ -147,8 +147,8 @@ struct tree_stores *setup_cell_selector(GtkTreeView* view, GtkEntry *search_entr
column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL); column = gtk_tree_view_column_new_with_attributes("Library", render_lib, "gds-lib", CELL_SEL_LIBRARY, NULL);
gtk_tree_view_append_column(view, column); gtk_tree_view_append_column(view, column);
/* Cell color: #3D9801 */ column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL,
column = gtk_tree_view_column_new_with_attributes("Cell", render_cell, "gds-cell", CELL_SEL_CELL, "foreground-rgba", CELL_SEL_CELL_COLOR, NULL); "error-level", CELL_SEL_CELL_ERROR_STATE, 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_dates, "text", CELL_SEL_MODDATE, NULL); column = gtk_tree_view_column_new_with_attributes("Mod. Date", render_dates, "text", CELL_SEL_MODDATE, NULL);

View File

@ -37,7 +37,7 @@
enum cell_store_columns { enum cell_store_columns {
CELL_SEL_LIBRARY = 0, CELL_SEL_LIBRARY = 0,
CELL_SEL_CELL, CELL_SEL_CELL,
CELL_SEL_CELL_COLOR, /**< Cell column color */ CELL_SEL_CELL_ERROR_STATE, /**< Used for cell color and selectability */
CELL_SEL_MODDATE, CELL_SEL_MODDATE,
CELL_SEL_ACCESSDATE, CELL_SEL_ACCESSDATE,
CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/ CELL_SEL_COLUMN_COUNT /**< Not a column. Used to determine count of coumns **/