X-Git-Url: http://git.maemo.org/git/?p=scdataviz;a=blobdiff_plain;f=scdataviz.c;h=4c0851d7ca31eece5c2645c5be9537b81a05a5dc;hp=1024a12275ebc422777c5f0805edc64fc9f2aa1e;hb=152331cb46d5b28d1586ce0fd0aaea3d53b440e0;hpb=07dd48ff5e45f3168ebaf267f33d92f5332c0b94 diff --git a/scdataviz.c b/scdataviz.c index 1024a12..4c0851d 100644 --- a/scdataviz.c +++ b/scdataviz.c @@ -6,20 +6,22 @@ ** ** Holds the SC graphing widget. -Copyright (C) 2008 Joseph Pingenot -This program is free software: you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. -This program 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. + Copyright (C) 2008 Joseph Pingenot -You should have received a copy of the GNU General Public License -along with this program. If not, see . + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program 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 Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . ** Started on Thu Jul 17 11:03:27 2008 Johnny Q. Hacker ** Last update Sun May 12 01:17:25 2002 Speed Blue @@ -27,23 +29,150 @@ along with this program. If not, see . #include #include +#include +#include +#include + +#define DEBUG_SHOW_ONLY_BOWED + +struct xy_properties { + GString *xprop; + GString *yprop; + Graph *graph; + struct matdb *mdb; + struct matdb_material *mat; +}; + +static void lookup_xy(GHashTable* propts, GString* xprop, GString* yprop, double **x, double **y) { + *x=g_hash_table_lookup(propts, xprop->str); + *y=g_hash_table_lookup(propts, yprop->str); +} + +static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) { + struct xy_properties *propmap = user_data; + struct matdb_material *mat = value; + if(!strcasecmp(mat->name->str, "vacuum")) return; + if(!strcasecmp(mat->name->str, "pvb")) return; + double *x, *y; + #ifdef DEBUG + fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str); + #endif + lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &x, &y); + if((x != NULL) && (y != NULL)) { + graph_add_point(propmap->graph, *x, *y, mat->name); + #ifdef DEBUG + fprintf(stderr, "added (x->%s=%g, y->%s=%g)\n", propmap->xprop->str, *x, propmap->yprop->str, *y); + }else{ + fprintf(stderr, "no such properties (x->%s, y->%s)\n", propmap->xprop->str, propmap->yprop->str); + #endif + } +} + +static void inner_link_materials(gpointer key, gpointer value, gpointer user_data) { + struct xy_properties *propmap = user_data; + struct matdb_material *mat = value; + if(!strcasecmp(mat->name->str, "vacuum")) return; + if(!strcasecmp(mat->name->str, "pvb")) return; + if(g_string_equal(mat->name, propmap->mat->name)) return; + struct graph_line *l = (struct graph_line *)malloc(sizeof(struct graph_line)); + if(l == NULL) return; + struct matdb_bowing *bow = NULL; + GHashTable *subtable; + double *p0_x, *p0_y, *p1_x, *p1_y, *p3_x, *p3_y; + lookup_xy(propmap->mat->properties, propmap->xprop, propmap->yprop, &p0_x, &p0_y); + lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &p3_x, &p3_y); +#ifdef DEBUG + fprintf(stderr, "%s:%s x=%s y=%s p0(%g,%g) p3(%g,%g)\n", propmap->mat->name->str, mat->name->str, propmap->xprop->str, propmap->yprop->str, (p0_x)?*p0_x:0, (p0_y)?*p0_y:0, (p3_x)?*p3_x:0, (p3_y)?*p3_y:0); +#endif + if((p0_x != NULL) && (p0_y != NULL) && (p3_x != NULL) && (p3_y != NULL)) { + l->p0_x = *p0_x; + l->p0_y = *p0_y; + l->p3_x = *p3_x; + l->p3_y = *p3_y; + if((subtable = g_hash_table_lookup(propmap->mdb->bowings, propmap->mat->name->str)) == NULL) { + /*Try the other way 'round*/ + if((subtable = g_hash_table_lookup(propmap->mdb->bowings, mat->name->str) ) + != NULL) { + bow = g_hash_table_lookup(subtable, propmap->mat->name->str); + } + }else{ + bow = g_hash_table_lookup(subtable, mat->name->str); + } + if(bow != NULL) { + if((p1_x = g_hash_table_lookup(bow->properties, propmap->xprop->str)) != NULL) { + l->p1_x = *p1_x/2.0; + graph_bezier_quadratic_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x)); + }else{ + graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x)); + } + if((p1_y = g_hash_table_lookup(bow->properties, propmap->yprop->str)) != NULL) { + l->p1_y = *p1_y/2.0; + graph_bezier_quadratic_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y)); + }else{ + graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y)); + } + }else{ + #ifdef DEBUG_SHOW_ONLY_BOWED + free(l); + return; + #endif; + graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x)); + graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y)); + } + #ifdef DEBUG + fprintf(stderr, "%s:%s p0(%g,%g) p1(%g,%g) p2(%g,%g), p3(%g,%g)\n", propmap->mat->name->str, mat->name->str, l->p0_x, l->p0_y, l->p1_x, l->p1_y, l->p2_x, l->p2_y, l->p3_x, l->p3_y); + #endif + graph_add_graph_line(propmap->graph, l); + }else{ + free(l); + } +} + +static void link_materials(gpointer key, gpointer value, gpointer user_data) { + struct xy_properties *propmap = user_data; + struct matdb_material *mat = value; + if(!strcasecmp(mat->name->str, "vacuum")) return; + if(!strcasecmp(mat->name->str, "pvb")) return; + propmap->mat = mat; + g_hash_table_foreach(propmap->mdb->materials, &inner_link_materials, propmap); +} int main(int argc, char *argv[]) { GtkWidget *window; - GtkWidget *button; GtkWidget *graph; + GString *file = g_string_new("../matdb"); + int err=0; + struct matdb *mdb = read_matdb_dotcode(file, &err); + //fprintf(stderr, "read_matdb_dotcode(%s, %d)=%x", file->str, err, + //(int)mdb); + fprintf(stderr, "err=%d\n", err); + //print_matdb(mdb); gtk_init (&argc, &argv); window = gtk_window_new (GTK_WINDOW_TOPLEVEL); graph = graph_widget_new(); - + + struct xy_properties propmap; + propmap.xprop = g_string_new("a_lc"); + propmap.yprop = g_string_new("E_g_Gamma"); + propmap.graph = graph_widget_get_graph(GRAPH_WIDGET(graph)); + propmap.mdb = mdb; + g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap); + //graph_add_linear_connectors(propmap.graph); + g_hash_table_foreach(mdb->materials, &link_materials, &propmap); + //Connect signals g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL); gtk_container_add(GTK_CONTAINER(window), graph); + /* + graph_add_point(graph_widget_get_graph(graph), 5, 3); + graph_add_point(graph_widget_get_graph(graph), 8, 12); + graph_add_point(graph_widget_get_graph(graph), 11, 48); + */ gtk_widget_show_all (window);