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 Sun May 12 01:17:25 2002 Speed Blue
31 #include <graphwidget.h>
32 #include <matdb-dotcode.h>
36 #define DEBUG_SHOW_ONLY_BOWED
38 struct xy_properties {
43 struct matdb_material *mat;
46 static void lookup_xy(GHashTable* propts, GString* xprop, GString* yprop, double **x, double **y) {
47 *x=g_hash_table_lookup(propts, xprop->str);
48 *y=g_hash_table_lookup(propts, yprop->str);
51 static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
52 struct xy_properties *propmap = user_data;
53 struct matdb_material *mat = value;
54 if(!strcasecmp(mat->name->str, "vacuum")) return;
55 if(!strcasecmp(mat->name->str, "pvb")) return;
57 #ifdef DEBUG_ASSIGNMENT
58 fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
60 lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &x, &y);
61 if((x != NULL) && (y != NULL)) {
62 graph_add_point(propmap->graph, *x, *y, mat->name);
63 #ifdef DEBUG_ASSIGNMENT
64 fprintf(stderr, "added (x->%s=%g, y->%s=%g)\n", propmap->xprop->str, *x, propmap->yprop->str, *y);
66 fprintf(stderr, "no such properties (x->%s, y->%s)\n", propmap->xprop->str, propmap->yprop->str);
71 static void inner_link_materials(gpointer key, gpointer value, gpointer user_data) {
72 struct xy_properties *propmap = user_data;
73 struct matdb_material *mat = value;
74 if(!strcasecmp(mat->name->str, "vacuum")) return;
75 if(!strcasecmp(mat->name->str, "pvb")) return;
76 if(g_string_equal(mat->name, propmap->mat->name)) return;
77 struct graph_line *l = (struct graph_line *)malloc(sizeof(struct graph_line));
79 struct matdb_bowing *bow = NULL;
81 double *p0_x, *p0_y, *p1_x, *p1_y, *p3_x, *p3_y;
82 lookup_xy(propmap->mat->properties, propmap->xprop, propmap->yprop, &p0_x, &p0_y);
83 lookup_xy(mat->properties, propmap->xprop, propmap->yprop, &p3_x, &p3_y);
84 #ifdef DEBUG_ASSIGNMENT
85 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);
87 if((p0_x != NULL) && (p0_y != NULL) && (p3_x != NULL) && (p3_y != NULL)) {
92 if((subtable = g_hash_table_lookup(propmap->mdb->bowings, propmap->mat->name->str)) == NULL) {
93 /*Try the other way 'round*/
94 if((subtable = g_hash_table_lookup(propmap->mdb->bowings, mat->name->str) )
96 bow = g_hash_table_lookup(subtable, propmap->mat->name->str);
99 bow = g_hash_table_lookup(subtable, mat->name->str);
102 if((p1_x = g_hash_table_lookup(bow->properties, propmap->xprop->str)) != NULL) {
104 graph_bezier_quadratic_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
106 graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
108 if((p1_y = g_hash_table_lookup(bow->properties, propmap->yprop->str)) != NULL) {
110 graph_bezier_quadratic_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
112 graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
115 #ifdef DEBUG_SHOW_ONLY_BOWED
119 graph_bezier_linear_to_cubic(l->p0_x, l->p3_x, &(l->p1_x), &(l->p2_x));
120 graph_bezier_linear_to_cubic(l->p0_y, l->p3_y, &(l->p1_y), &(l->p2_y));
122 #ifdef DEBUG_ASSIGNMENT
123 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);
125 graph_add_graph_line(propmap->graph, l);
131 static void link_materials(gpointer key, gpointer value, gpointer user_data) {
132 struct xy_properties *propmap = user_data;
133 struct matdb_material *mat = value;
134 if(!strcasecmp(mat->name->str, "vacuum")) return;
135 if(!strcasecmp(mat->name->str, "pvb")) return;
137 g_hash_table_foreach(propmap->mdb->materials, &inner_link_materials, propmap);
140 int main(int argc, char *argv[])
144 GString *file = g_string_new("../matdb");
146 struct matdb *mdb = read_matdb_dotcode(file, &err);
147 //fprintf(stderr, "read_matdb_dotcode(%s, %d)=%x", file->str, err,
149 fprintf(stderr, "err=%d\n", err);
152 gtk_init (&argc, &argv);
154 window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
155 graph = graph_widget_new();
157 struct xy_properties propmap;
158 propmap.xprop = g_string_new("a_lc");
159 propmap.yprop = g_string_new("E_g_Gamma");
160 propmap.graph = graph_widget_get_graph(GRAPH_WIDGET(graph));
162 g_hash_table_foreach(mdb->materials, &put_mat_in_graph, &propmap);
163 //graph_add_linear_connectors(propmap.graph);
164 g_hash_table_foreach(mdb->materials, &link_materials, &propmap);
165 graph_autoset_xaxis(propmap.graph, propmap.xprop);
166 graph_autoset_yaxis(propmap.graph, propmap.yprop);
169 g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(gtk_main_quit), NULL);
171 gtk_container_add(GTK_CONTAINER(window), graph);
173 graph_add_point(graph_widget_get_graph(graph), 5, 3);
174 graph_add_point(graph_widget_get_graph(graph), 8, 12);
175 graph_add_point(graph_widget_get_graph(graph), 11, 48);
178 gtk_widget_show_all (window);