* Seems to be coming along. Not convinced that the bowing conversions are right.
[scdataviz] / scdataviz.c
index c51f21d..bfed526 100644 (file)
 #include <gtk/gtk.h>
 #include <graphwidget.h>
 #include <matdb-dotcode.h>
 #include <gtk/gtk.h>
 #include <graphwidget.h>
 #include <matdb-dotcode.h>
+#include <stdlib.h>
+#include <strings.h>
 
 
-#undef DEBUG
+#define DEBUG_SHOW_ONLY_BOWED
 
 struct xy_properties {
   GString *xprop;
   GString *yprop;
   Graph *graph;
 
 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;
 static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
   struct xy_properties *propmap = user_data;
   struct matdb_material *mat = value;
@@ -48,8 +57,8 @@ static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
   #ifdef DEBUG
   fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
   #endif
   #ifdef DEBUG
   fprintf(stderr, "put_mat_in_graph(%s) (x->%s, y->%s): ", (char*)key, propmap->xprop->str, propmap->yprop->str);
   #endif
-  if(((x=g_hash_table_lookup(mat->properties, propmap->xprop->str)) != NULL)
-     && ((y=g_hash_table_lookup(mat->properties, propmap->yprop->str)) != NULL)) {
+  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);
     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);
@@ -59,10 +68,78 @@ static void put_mat_in_graph(gpointer key, gpointer value, gpointer user_data) {
   }
 }
 
   }
 }
 
+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;
+       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;
+       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;
 int main(int   argc, char *argv[]) 
 {
     GtkWidget *window;
-    GtkWidget *button;
     GtkWidget *graph;
     GString *file = g_string_new("../matdb");
     int err=0;
     GtkWidget *graph;
     GString *file = g_string_new("../matdb");
     int err=0;
@@ -72,10 +149,7 @@ int main(int   argc, char *argv[])
     fprintf(stderr, "err=%d\n", err);
     //print_matdb(mdb);
     
     fprintf(stderr, "err=%d\n", err);
     //print_matdb(mdb);
     
-    
     gtk_init (&argc, &argv);
     gtk_init (&argc, &argv);
-
-    
     
     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     graph = graph_widget_new();
     
     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
     graph = graph_widget_new();
@@ -84,7 +158,10 @@ int main(int   argc, char *argv[])
     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.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);
     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
 
 
     //Connect signals