4 ** Made by (Johnny Q. Hacker)
5 ** Login <solarion@johnathan>
7 ** Holds the SC graphing widget.
11 Copyright (C) 2008 Joseph Pingenot
13 This program is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Affero General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Affero General Public License for more details.
23 You should have received a copy of the GNU Affero General Public License
24 along with this program. If not, see <http://www.gnu.org/licenses/>.
26 ** Started on Thu Jul 17 11:03:27 2008 Johnny Q. Hacker
27 ** Last update Thu Oct 15 21:51:34 2009 Johnny Q. Hacker
34 #include "matdb-dotcode.h"
35 #include "graphwidget.h"
37 #define DEBUG_SHOW_ONLY_BOWED
39 struct xy_properties {
44 struct matdb_material *mat;
47 static void lookup_xy(GHashTable* propts, GString* xprop, GString* yprop, double **x, double **y) {
48 *x=g_hash_table_lookup(propts, xprop->str);
49 *y=g_hash_table_lookup(propts, yprop->str);
52 static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
53 struct xy_properties *propmap = user_data;
54 struct matdb_material *mat = value;
55 if(!strcasecmp(mat->name->str, "vacuum")) return;
56 if(!strcasecmp(mat->name->str, "pvb")) return;
58 #ifdef DEBUG_ASSIGNMENT
59 fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
61 lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &x, &y);
62 if((x != NULL) && (y != NULL)) {
63 graph_add_point(propmap->graph, *x, *y, mat->name);
64 #ifdef DEBUG_ASSIGNMENT
65 fprintf(stderr, "added (x->%s=%g, y->%s=%g)\n", propmap->xprop->str, *x, propmap->yprop->str, *y);
67 fprintf(stderr, "no such properties (x->%s, y->%s)\n", propmap->xprop->str, propmap->yprop->str);
72 static void inner_link_materials(gpointer key, gpointer value, gpointer user_data) {
73 struct xy_properties *propmap = user_data;
74 struct matdb_material *mat = value;
75 if(!strcasecmp(mat->name->str, "vacuum")) return;
76 if(!strcasecmp(mat->name->str, "pvb")) return;
77 if(g_string_equal(mat->name, propmap->mat->name)) return;
78 struct graph_line *l = (struct graph_line *)malloc(sizeof(struct graph_line));
80 struct matdb_bowing *bow = NULL;
82 double *p0_x, *p0_y, *p1_x, *p1_y, *p3_x, *p3_y;
83 lookup_xy(propmap->mat->properties, propmap->xprop, propmap->yprop, &p0_x, &p0_y);
84 lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &p3_x, &p3_y);
85 #ifdef DEBUG_ASSIGNMENT
86 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);
88 if((p0_x != NULL) && (p0_y != NULL) && (p3_x != NULL) && (p3_y != NULL)) {
93 if((subtable = g_hash_table_lookup(propmap->mdb->bowings, propmap->mat->name->str)) == NULL) {
94 /*Try the other way 'round*/
95 if((subtable = g_hash_table_lookup(propmap->mdb->bowings, mat->name->str) )
97 bow = g_hash_table_lookup(subtable, propmap->mat->name->str);
100 bow = g_hash_table_lookup(subtable, mat->name->str);
103 if((p1_x = g_hash_table_lookup(bow->properties, propmap->xprop->str)) != NULL) {
105 graph_bezier_quadratic_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
107 graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
109 if((p1_y = g_hash_table_lookup(bow->properties, propmap->yprop->str)) != NULL) {
111 graph_bezier_quadratic_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
113 graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
116 #ifdef DEBUG_SHOW_ONLY_BOWED
120 graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
121 graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
123 #ifdef DEBUG_ASSIGNMENT
124 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);
126 graph_add_graph_line(propmap->graph, l);
132 static void link_materials(gpointer key, gpointer value, gpointer user_data) {
133 struct xy_properties *propmap = user_data;
134 struct matdb_material *mat = value;
135 if(!strcasecmp(mat->name->str, "vacuum")) return;
136 if(!strcasecmp(mat->name->str, "pvb")) return;
138 g_hash_table_foreach(propmap->mdb->materials, &inner_link_materials, propmap);
141 int main(int argc, char *argv[])
145 GString *file = g_string_new("matdb.txt");
147 struct matdb *mdb = read_matdb_dotcode(file, &err);
148 //fprintf(stderr, "read_matdb_dotcode(%s, %d)=%x", file->str, err,
150 //fprintf(stderr, "err=%d\n", err);
153 gtk_init (&argc, &argv);
155 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
156 graph = graph_widget_new();
158 struct xy_properties propmap;
159 propmap.xprop = g_string_new("a_lc");
160 propmap.yprop = g_string_new("E_g_Gamma");
161 propmap.graph = graph_widget_get_graph(GRAPH_WIDGET(graph));
163 g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap);
164 //graph_add_linear_connectors(propmap.graph);
165 g_hash_table_foreach(mdb->materials, &link_materials, &propmap);
166 graph_autoset_xaxis(propmap.graph, propmap.xprop);
167 graph_autoset_yaxis(propmap.graph, propmap.yprop);
170 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
172 gtk_container_add(GTK_CONTAINER(window), graph);
174 graph_add_point(graph_widget_get_graph(graph), 5, 3);
175 graph_add_point(graph_widget_get_graph(graph), 8, 12);
176 graph_add_point(graph_widget_get_graph(graph), 11, 48);
179 gtk_widget_show_all (window);