[xiph-commits] r12661 - trunk/sushivision

xiphmont at svn.xiph.org xiphmont at svn.xiph.org
Tue Mar 6 05:23:45 PST 2007


Author: xiphmont
Date: 2007-03-06 05:23:40 -0800 (Tue, 06 Mar 2007)
New Revision: 12661

Modified:
   trunk/sushivision/Makefile
   trunk/sushivision/dimension.c
   trunk/sushivision/dimension.h
   trunk/sushivision/example_chirp.c
   trunk/sushivision/example_discrete.c
   trunk/sushivision/example_fractal.c
   trunk/sushivision/internal.h
   trunk/sushivision/main.c
   trunk/sushivision/panel-1d.c
   trunk/sushivision/panel-2d.c
   trunk/sushivision/panel.c
   trunk/sushivision/sushi-gtkrc.in
   trunk/sushivision/sushivision.h
   trunk/sushivision/undo.c
Log:
Incremental commit while implementing save/load.



Modified: trunk/sushivision/Makefile
===================================================================
--- trunk/sushivision/Makefile	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/Makefile	2007-03-06 13:23:40 UTC (rev 12661)
@@ -34,27 +34,24 @@
 OBJ       = main.o scale.o plot.o slider.o slice.o spinner.c panel.o panel-1d.o panel-2d.o \
 	mapping.o dimension.o function.o objective.o undo.o gtksucks.o
 LIBS      = -lpthread -ldl
-CAIROVER  =  >= 1.3.14
+CAIROVER  =  >= 1.3.16
 GTKVER    =  >= 2.10.0
-GCF       = -std=gnu99 `pkg-config --cflags "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) cairo-ft $(CAIROVER) gthread-2.0"`
-LDF       = -pthread -L/lib -ldl -rdynamic \
-	`pkg-config --libs "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) cairo-ft $(CAIROVER) gthread-2.0"`
+PKGARG	  = "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) cairo-ft $(CAIROVER) gthread-2.0 libxml-2.0"
+GCF       = -std=gnu99 `pkg-config --cflags $(PKGARG)`
+LDF       = -pthread -L/lib -ldl -rdynamic `pkg-config --libs $(PKGARG)`
 
 all:    
-	pkg-config --cflags "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) gthread-2.0 cairo-ft" \
-		1>/dev/null
+	pkg-config --cflags $(PKGARG) 1>/dev/null
 	$(MAKE) target CFLAGS='-O2 -g $(SOCFLAGS) $(GCF) $(ADD_DEF)'
 	$(MAKE) examples CFLAGS='-O2 -g $(GCF) $(ADD_DEF)'
 
 debug:
-	pkg-config --cflags "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) gthread-2.0 cairo-ft" \
-		1>/dev/null
+	pkg-config --cflags $(PKGARG) 1>/dev/null
 	$(MAKE) target CFLAGS='-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(SOCFLAGS) $(GCF) $(ADD_DEF)'
 	$(MAKE) examples CFLAGS='-g -Wall -W -Wno-unused-parameter -D__NO_MATH_INLINES $(GCF) $(ADD_DEF)'
 
 profile:
-	pkg-config --cflags "gtk+-2.0 $(GTKVER) cairo $(CAIROVER) gthread-2.0 freetype2" \
-		1>/dev/null
+	pkg-config --cflags $(PKGARG) 1>/dev/null
 	$(MAKE) examples CFLAGS='-pg -g -O2 $(GCF) $(ADD_DEF)' 
 
 clean:

Modified: trunk/sushivision/dimension.c
===================================================================
--- trunk/sushivision/dimension.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/dimension.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -759,3 +759,44 @@
   return 0;
 
 }
+
+int save_dimension(sushiv_dimension_t *d, xmlNodePtr instance){  
+  if(!d) return 0;
+  char buffer[80];
+  int ret=0;
+
+  xmlNodePtr dn = xmlNewChild(instance, NULL, (xmlChar *) "dimension", NULL);
+
+  snprintf(buffer,sizeof(buffer),"%d",d->number);
+  xmlNewProp(dn, (xmlChar *)"number", (xmlChar *)buffer);
+  if(d->name)
+    xmlNewProp(dn, (xmlChar *)"name", (xmlChar *)d->name);
+
+  switch(d->type){
+  case SUSHIV_DIM_CONTINUOUS:
+    xmlNewProp(dn, (xmlChar *)"type", (xmlChar *)"continuous");
+    break;
+  case SUSHIV_DIM_DISCRETE:
+    xmlNewProp(dn, (xmlChar *)"type", (xmlChar *)"discrete");
+    break;
+  case SUSHIV_DIM_PICKLIST:
+    xmlNewProp(dn, (xmlChar *)"type", (xmlChar *)"picklist");
+    break;
+  }
+
+  switch(d->type){
+  case SUSHIV_DIM_CONTINUOUS:
+  case SUSHIV_DIM_DISCRETE:
+    snprintf(buffer,sizeof(buffer),"%.20g",d->bracket[0]);
+    xmlNewChild(dn, NULL, (xmlChar *) "low-bracket", (xmlChar *)buffer);
+    snprintf(buffer,sizeof(buffer),"%.20g",d->bracket[1]);
+    xmlNewChild(dn, NULL, (xmlChar *) "high-bracket", (xmlChar *)buffer);
+    
+  case SUSHIV_DIM_PICKLIST:
+    snprintf(buffer,sizeof(buffer),"%.20g",d->val);
+    xmlNewChild(dn, NULL, (xmlChar *) "value", (xmlChar *)buffer);
+    break;
+  }
+
+  return ret;
+}

Modified: trunk/sushivision/dimension.h
===================================================================
--- trunk/sushivision/dimension.h	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/dimension.h	2007-03-06 13:23:40 UTC (rev 12661)
@@ -72,3 +72,4 @@
 extern sushiv_dim_widget_t *_sushiv_new_dimension_widget(sushiv_dimension_list_t *dl,   
 							 void (*center_callback)(sushiv_dimension_list_t *),
 							 void (*bracket_callback)(sushiv_dimension_list_t *));
+extern int save_dimension(sushiv_dimension_t *d, xmlNodePtr instance);

Modified: trunk/sushivision/example_chirp.c
===================================================================
--- trunk/sushivision/example_chirp.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/example_chirp.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -49,7 +49,7 @@
 
 int sushiv_submain(int argc, char *argv[]){
 
-  s=sushiv_new_instance();
+  s=sushiv_new_instance(0,"chirp");
 
   sushiv_new_dimension(s,0,"initial Hz",
 		       4,(double []){1,10,100,1000},

Modified: trunk/sushivision/example_discrete.c
===================================================================
--- trunk/sushivision/example_discrete.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/example_discrete.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -39,7 +39,7 @@
 
 int sushiv_submain(int argc, char *argv[]){
 
-  s=sushiv_new_instance();
+  s=sushiv_new_instance(0,NULL);
 
   sushiv_new_dimension_discrete(s,0,"A",
 				5,(double []){-500,-10,0,10,500},

Modified: trunk/sushivision/example_fractal.c
===================================================================
--- trunk/sushivision/example_fractal.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/example_fractal.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -52,7 +52,7 @@
 
 int sushiv_submain(int argc, char *argv[]){
 
-  s=sushiv_new_instance();
+  s=sushiv_new_instance(0,"fractal");
 
   sushiv_new_dimension(s,0,"Re(c)",
 		       5,(double []){-2.25,-0.75,0,0.25,0.75},

Modified: trunk/sushivision/internal.h
===================================================================
--- trunk/sushivision/internal.h	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/internal.h	2007-03-06 13:23:40 UTC (rev 12661)
@@ -22,6 +22,8 @@
 #include <time.h>
 #include <signal.h>
 #include <gtk/gtk.h>
+#include <libxml/parser.h>
+#include <libxml/tree.h>
 #include "sushivision.h"
 #include "mapping.h"
 #include "slice.h"
@@ -122,10 +124,15 @@
   void (*undo_restore)(sushiv_panel_undo_t *u, sushiv_panel_t *p);
 };
 
+typedef struct sushiv_instance_undo {
+  sushiv_panel_undo_t *panels;
+  double *dim_vals[3];
+} sushiv_instance_undo_t;
+
 struct sushiv_instance_internal {
   int undo_level;
   int undo_suspend;
-  sushiv_panel_undo_t **undo_stack;
+  sushiv_instance_undo_t **undo_stack;
 };
 
 extern void _sushiv_realize_panel(sushiv_panel_t *p);
@@ -164,4 +171,11 @@
 extern void _sushiv_panel1d_update_linked_crosshairs(sushiv_panel_t *p, int xflag, int yflag); 
 extern void _sushiv_panel_update_menus(sushiv_panel_t *p);
 
+extern int save_main();
+extern int save_panel(sushiv_panel_t *p, xmlNodePtr instance);
+
 extern sig_atomic_t _sushiv_exiting;
+extern char *filebase;
+extern char *filename;
+extern char *dirname;
+extern char *cwdname;

Modified: trunk/sushivision/main.c
===================================================================
--- trunk/sushivision/main.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/main.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -183,21 +183,45 @@
 
 /* externally visible interface */
 
-sushiv_instance_t *sushiv_new_instance(void) {
-  sushiv_instance_t *ret=calloc(1,sizeof(*ret));
-  ret->private = calloc(1,sizeof(*ret->private));
+sushiv_instance_t *sushiv_new_instance(int number, char *name) {
+  sushiv_instance_t *ret;
 
-  if(instances){
-    instance_list = realloc(instance_list,(instances+1)*sizeof(*instance_list));
+  if(number<0){
+    fprintf(stderr,"Instance number must be >= 0\n");
+    errno = -EINVAL;
+    return NULL;
+  }
+  
+  if(number<instances){
+    if(instance_list[number]!=NULL){
+      fprintf(stderr,"Instance number %d already exists\n",number);
+      errno = -EINVAL;
+      return NULL;
+    }
   }else{
-    instance_list = malloc((instances+1)*sizeof(*instance_list));
+    if(instances == 0){
+      instance_list = calloc (number+1,sizeof(*instance_list));
+    }else{
+      instance_list = realloc (instance_list,(number+1) * sizeof(*instance_list));
+      memset(instance_list + instances, 0, sizeof(*instance_list)*(number+1 - instances));
+    }
+    instances = number+1; 
   }
-  instance_list[instances] = ret;
-  instances++;
-  
+
+  ret = instance_list[number] = calloc(1, sizeof(**instance_list));
+  ret->private = calloc(1,sizeof(*ret->private));
+  if(name)
+    ret->name = strdup(name);
+
   return ret;
 }
 
+char *appname = NULL;
+char *filename = NULL;
+char *filebase = NULL;
+char *dirname = NULL;
+char *cwdname = NULL;
+
 int main (int argc, char *argv[]){
   int ret;
 
@@ -217,6 +241,48 @@
   sushiv_realize_all();
   gtk_button3_fixup();
   
+  appname = g_get_prgname ();
+  cwdname = getcwd(NULL,0);
+  dirname = strdup(cwdname);
+  if(argc>1){
+    // file to load specified on commandline
+    filebase = strdup(argv[argc-1]);
+    char *base = strrchr(filebase,'/');
+    
+    // filebase may include a path; pull it off and apply it toward dirname
+    if(base){
+      base[0] = '\0';
+      char *dirbit = strdup(filebase);
+      filebase = base+1;
+      if(g_path_is_absolute(dirbit)){
+	// replace dirname
+	free(dirname);
+	dirname = dirbit;
+      }else{
+	// append to dirname
+	char *buf;
+	asprintf(&buf,"%s/%s",dirname,dirbit);
+	free(dirname);
+	dirname = buf;
+      }
+    }
+    
+    // load the state file
+
+  }else{
+    if(appname){
+      char *base = strrchr(appname,'/');
+      if(!base) 
+	base = appname;
+      else
+	base++;
+
+      asprintf(&filebase, "%s.sushi",base);
+    }else
+      filebase = strdup("default.sushi");
+  }
+  asprintf(&filename,"%s/%s",dirname,filebase);
+
   {
     pthread_t dummy;
     int threads = num_threads;
@@ -227,6 +293,7 @@
   signal(SIGINT,_sushiv_clean_exit);
   //signal(SIGSEGV,_sushiv_clean_exit);
 
+
   gtk_main ();
   gdk_threads_leave();
   
@@ -239,3 +306,50 @@
   return 0;
 }
 
+int save_instance(sushiv_instance_t *s, xmlNodePtr root){
+  if(!s) return 0;
+  char buffer[80];
+  int i, ret=0;
+
+  xmlNodePtr instance = xmlNewChild(root, NULL, (xmlChar *) "instance", NULL);
+
+  snprintf(buffer,sizeof(buffer),"%d",s->number);
+  xmlNewProp(instance, (xmlChar *)"number", (xmlChar *)buffer);
+  if(s->name)
+    xmlNewProp(instance, (xmlChar *)"name", (xmlChar *)s->name);
+  
+  // dimension values are independent of panel
+  for(i=0;i<s->dimensions;i++)
+    ret|=save_dimension(s->dimension_list[i], instance);
+  
+  // objectives have no independent settings
+
+  // panel settings (by panel)
+  for(i=0;i<s->panels;i++)
+    ret|=save_panel(s->panel_list[i], instance);
+
+  return ret;
+}
+
+int save_main(){
+  xmlDocPtr doc = NULL;
+  xmlNodePtr root_node = NULL;
+  int i, ret=0;
+
+  LIBXML_TEST_VERSION;
+
+  doc = xmlNewDoc((xmlChar *)"1.0");
+  root_node = xmlNewNode(NULL, (xmlChar *)appname);
+  xmlDocSetRootElement(doc, root_node);
+
+  // save each instance 
+  for(i=0;i<instances;i++)
+   ret |= save_instance(instance_list[i],root_node);
+
+  xmlSaveFormatFileEnc(filename, doc, "UTF-8", 1);
+
+  xmlFreeDoc(doc);
+  xmlCleanupParser();
+
+  return ret;
+}

Modified: trunk/sushivision/panel-1d.c
===================================================================
--- trunk/sushivision/panel-1d.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/panel-1d.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -1119,12 +1119,6 @@
     u->scale_vals[1] =  calloc(1,sizeof(**u->scale_vals));
   if(!u->scale_vals[2])
     u->scale_vals[2] =  calloc(p->objectives,sizeof(**u->scale_vals));
-  if(!u->dim_vals[0])
-    u->dim_vals[0] =  calloc(p->dimensions+1,sizeof(**u->dim_vals)); // +1 for possible linked dim
-  if(!u->dim_vals[1])
-    u->dim_vals[1] =  calloc(p->dimensions+1,sizeof(**u->dim_vals)); // +1 for possible linked dim
-  if(!u->dim_vals[2])
-    u->dim_vals[2] =  calloc(p->dimensions+1,sizeof(**u->dim_vals)); // +1 for possible linked dim
 
   // populate undo
   u->scale_vals[0][0] = slider_get_value(p1->range_slider,0);
@@ -1138,16 +1132,6 @@
     u->scale_vals[2][0] = slider_get_value(p1->alpha_scale[i],0);
   }
 
-  for(i=0;i<p->dimensions;i++){
-    u->dim_vals[0][i] = p->dimension_list[i].d->bracket[0];
-    u->dim_vals[1][i] = p->dimension_list[i].d->val;
-    u->dim_vals[2][i] = p->dimension_list[i].d->bracket[1];
-  }
-
-  u->dim_vals[0][i] = p1->x_d->bracket[0];
-  u->dim_vals[1][i] = p1->x_d->val;
-  u->dim_vals[2][i] = p1->x_d->bracket[1];
-
   u->x_d = p1->x_dnum;
   u->box[0] = p1->oldbox[0];
   u->box[1] = p1->oldbox[1];
@@ -1174,12 +1158,6 @@
     slider_set_value(p1->alpha_scale[i],0,u->scale_vals[2][i]);
   }
 
-  for(i=0;i<p->dimensions;i++){
-    _sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
-    _sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
-    _sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
-  }
-
   if(p1->dim_xb && u->x_d<p->dimensions && p1->dim_xb[u->x_d])
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p1->dim_xb[u->x_d]),TRUE);
 
@@ -1194,6 +1172,8 @@
   }
 
   if(u->box_active){
+    p1->oldbox[0] = u->box[0];
+    p1->oldbox[1] = u->box[1];
     plot_box_set(plot,u->box);
     p->private->oldbox_active = 1;
   }else{

Modified: trunk/sushivision/panel-2d.c
===================================================================
--- trunk/sushivision/panel-2d.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/panel-2d.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -1615,12 +1615,6 @@
     u->scale_vals[1] =  calloc(p->objectives,sizeof(**u->scale_vals));
   if(!u->scale_vals[2])
     u->scale_vals[2] =  calloc(p->objectives,sizeof(**u->scale_vals));
-  if(!u->dim_vals[0])
-    u->dim_vals[0] =  calloc(p->dimensions,sizeof(**u->dim_vals));
-  if(!u->dim_vals[1])
-    u->dim_vals[1] =  calloc(p->dimensions,sizeof(**u->dim_vals));
-  if(!u->dim_vals[2])
-    u->dim_vals[2] =  calloc(p->dimensions,sizeof(**u->dim_vals));
 
   // populate undo
   for(i=0;i<p->objectives;i++){
@@ -1629,12 +1623,6 @@
     u->scale_vals[1][i] = slider_get_value(p2->range_scales[i],1);
     u->scale_vals[2][i] = slider_get_value(p2->range_scales[i],2);
   }
-
-  for(i=0;i<p->dimensions;i++){
-    u->dim_vals[0][i] = p->dimension_list[i].d->bracket[0];
-    u->dim_vals[1][i] = p->dimension_list[i].d->val;
-    u->dim_vals[2][i] = p->dimension_list[i].d->bracket[1];
-  }
   
   u->x_d = p2->x_dnum;
   u->y_d = p2->y_dnum;
@@ -1658,18 +1646,16 @@
     slider_set_value(p2->range_scales[i],2,u->scale_vals[2][i]);
   }
 
-  for(i=0;i<p->dimensions;i++){
-    _sushiv_dimension_set_value(p->private->dim_scales[i],0,u->dim_vals[0][i]);
-    _sushiv_dimension_set_value(p->private->dim_scales[i],1,u->dim_vals[1][i]);
-    _sushiv_dimension_set_value(p->private->dim_scales[i],2,u->dim_vals[2][i]);
-  }
-
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p2->dim_xb[u->x_d]),TRUE);
   gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(p2->dim_yb[u->y_d]),TRUE);
 
   update_xy_availability(p);
 
   if(u->box_active){
+    p2->oldbox[0] = u->box[0];
+    p2->oldbox[1] = u->box[1];
+    p2->oldbox[2] = u->box[2];
+    p2->oldbox[3] = u->box[3];
     plot_box_set(plot,u->box);
     p->private->oldbox_active = 1;
   }else{

Modified: trunk/sushivision/panel.c
===================================================================
--- trunk/sushivision/panel.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/panel.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -418,9 +418,64 @@
   _sushiv_undo_up(p->sushi);
 }
 
+static void do_save(sushiv_panel_t *p){
+  GtkWidget *dialog = gtk_file_chooser_dialog_new ("Save",
+						   NULL,
+						   GTK_FILE_CHOOSER_ACTION_SAVE,
+						   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+						   GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+						   NULL);
+
+  gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
+  gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), cwdname, NULL);
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dirname);
+  gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), filebase);
+
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
+    if(filebase)free(filebase);
+    if(filename)free(filename);
+    if(dirname)free(dirname);
+
+    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+    dirname = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+    filebase = g_path_get_basename(filename);
+    save_main();
+  }
+
+  gtk_widget_destroy (dialog);
+
+}
+
+static void do_load(sushiv_panel_t *p){
+  GtkWidget *dialog = gtk_file_chooser_dialog_new ("Open",
+						   NULL,
+						   GTK_FILE_CHOOSER_ACTION_OPEN,
+						   GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+						   GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+						   NULL);
+
+  gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), cwdname, NULL);
+  gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), dirname);
+
+  if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT){
+    if(filebase)free(filebase);
+    if(filename)free(filename);
+    if(dirname)free(dirname);
+
+    filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
+    dirname = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (dialog));
+    filebase = g_path_get_basename(filename);
+
+    //_sushiv_panel_load();
+  }
+
+  gtk_widget_destroy (dialog);
+
+}
+
 static menuitem *menu[]={
-  &(menuitem){"Open","[<i>o</i>]",NULL,NULL},
-  &(menuitem){"Save","[<i>s</i>]",NULL,NULL},
+  &(menuitem){"Open","[<i>o</i>]",NULL,&do_load},
+  &(menuitem){"Save","[<i>s</i>]",NULL,&do_save},
   &(menuitem){"Print/Export","[<i>p</i>]",NULL,&_sushiv_panel_print},
 
   &(menuitem){"",NULL,NULL,NULL},
@@ -929,3 +984,39 @@
   p->private->undo_restore(u,p);
   _sushiv_panel_dirty_legend(p); 
 }
+
+int save_panel(sushiv_panel_t *p, xmlNodePtr instance){  
+  if(!p) return 0;
+  char buffer[80];
+  int ret=0;
+
+  xmlNodePtr pn = xmlNewChild(instance, NULL, (xmlChar *) "panel", NULL);
+
+  snprintf(buffer,sizeof(buffer),"%d",p->number);
+  xmlNewProp(pn, (xmlChar *)"number", (xmlChar *)buffer);
+  if(p->name)
+    xmlNewProp(pn, (xmlChar *)"name", (xmlChar *)p->name);
+
+  // let the panel subtype handler fill in type
+  // we're only saving settings independent of subtype
+
+  // background
+  switch(p->private->bg_type){
+  case 0:
+    xmlNewChild(pn, NULL, (xmlChar *) "background", (xmlChar *) "white");
+    break;
+  case 1:
+    xmlNewChild(pn, NULL, (xmlChar *) "background", (xmlChar *) "black");
+    break;
+  case 2:
+    xmlNewChild(pn, NULL, (xmlChar *) "background", (xmlChar *) "checked");
+    break;
+  }
+
+  // box
+  xmlNodePtr boxn = xmlNewChild(pn, NULL, (xmlChar *) "box", NULL);
+  snprintf(buffer,sizeof(buffer),"%d",p->private->oldbox_active);
+  xmlNewProp(boxn, (xmlChar *)"active", (xmlChar *)buffer);
+
+  return ret;
+}

Modified: trunk/sushivision/sushi-gtkrc.in
===================================================================
--- trunk/sushivision/sushi-gtkrc.in	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/sushi-gtkrc.in	2007-03-06 13:23:40 UTC (rev 12661)
@@ -93,8 +93,8 @@
 
 style "panel" {
 	bg[NORMAL]="#a0a0a0" 
-	bg[ACTIVE]="#c0f0ff" 
-	bg[PRELIGHT]="#c0f0ff" 
+	bg[ACTIVE]="#80a0ff" 
+	bg[PRELIGHT]="#c0f0ff"  
 
 	text[INSENSITIVE]="#606060"
 	text[NORMAL]="#000000"
@@ -104,11 +104,18 @@
 	font_name = "sans 9"
 }
 
+style "scale-poppy" {
+	bg[NORMAL]="#80a0ff" 
+	bg[ACTIVE]="#c0c0c0" 
+	bg[PRELIGHT]="#c0f0ff"  
+}
+
 style "panel-text" {
 	font_name = "sans"	
 }
 
 widget "*" style "panel"
+widget "*.GtkScrolledWindow*" style "scale-poppy"
 widget "*.GtkLabel" style "panel-text"
 widget "*.GtkMenu*" style "button-poppy"
 widget "*.GtkComboBox*" style "button-poppy"

Modified: trunk/sushivision/sushivision.h
===================================================================
--- trunk/sushivision/sushivision.h	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/sushivision.h	2007-03-06 13:23:40 UTC (rev 12661)
@@ -31,6 +31,9 @@
 typedef struct sushiv_instance_internal sushiv_instance_internal_t;
 
 typedef struct sushiv_instance {
+  int number;
+  char *name;
+
   int functions;
   sushiv_function_t **function_list;
 
@@ -160,7 +163,7 @@
   sushiv_panel_internal_t *private;
 };
 
-extern sushiv_instance_t *sushiv_new_instance(void);
+extern sushiv_instance_t *sushiv_new_instance(int number, char *name);
 
 extern void scale_free(sushiv_scale_t *s);
 extern sushiv_scale_t *scale_new(unsigned scalevals, 

Modified: trunk/sushivision/undo.c
===================================================================
--- trunk/sushivision/undo.c	2007-03-06 13:02:04 UTC (rev 12660)
+++ trunk/sushivision/undo.c	2007-03-06 13:23:40 UTC (rev 12661)
@@ -50,49 +50,77 @@
 }
 
 void _sushiv_undo_log(sushiv_instance_t *s){
-  sushiv_panel_undo_t *u;
+  sushiv_instance_undo_t *u;
   int i,j;
 
   if(!s->private->undo_stack)
-    s->private->undo_stack = calloc(2,s->panels*sizeof(*s->private->undo_stack));
+    s->private->undo_stack = calloc(2,sizeof(*s->private->undo_stack));
 
   // log into a fresh entry; pop this level and all above it 
   if(s->private->undo_stack[s->private->undo_level]){
     i=s->private->undo_level;
     while(s->private->undo_stack[i]){
-      for(j=0;j<s->panels;j++){
-	u = s->private->undo_stack[i]+j;
-	if(u->mappings) free(u->mappings);
-	if(u->scale_vals[0]) free(u->scale_vals[0]);
-	if(u->scale_vals[1]) free(u->scale_vals[1]);
-	if(u->scale_vals[2]) free(u->scale_vals[2]);
-	if(u->dim_vals[0]) free(u->dim_vals[0]);
-	if(u->dim_vals[1]) free(u->dim_vals[1]);
-	if(u->dim_vals[2]) free(u->dim_vals[2]);
+      u = s->private->undo_stack[i];
+
+      if(u->dim_vals[0]) free(u->dim_vals[0]);
+      if(u->dim_vals[1]) free(u->dim_vals[1]);
+      if(u->dim_vals[2]) free(u->dim_vals[2]);
+      
+      if(u->panels){
+	for(j=0;j<s->panels;j++){
+	  sushiv_panel_undo_t *pu = u->panels+j;
+	  if(pu->mappings) free(pu->mappings);
+	  if(pu->scale_vals[0]) free(pu->scale_vals[0]);
+	  if(pu->scale_vals[1]) free(pu->scale_vals[1]);
+	  if(pu->scale_vals[2]) free(pu->scale_vals[2]);
+	}
+	free(u->panels);
       }
       free(s->private->undo_stack[i]);
       s->private->undo_stack[i]= NULL;
       i++;
     }
   }
+  
+  // alloc new undos
+  u = s->private->undo_stack[s->private->undo_level] = calloc(1,sizeof(*u));
+  u->panels = calloc(s->panels,sizeof(*u->panels));
+  u->dim_vals[0] = calloc(s->dimensions,sizeof(**u->dim_vals));
+  u->dim_vals[1] = calloc(s->dimensions,sizeof(**u->dim_vals));
+  u->dim_vals[2] = calloc(s->dimensions,sizeof(**u->dim_vals));
 
-  // alloc new undos
-  u = s->private->undo_stack[s->private->undo_level]= calloc(s->panels,sizeof(*u));
-  
-  // pass off actual population to panels
+  // save dim values
+  for(i=0;i<s->dimensions;i++){
+    sushiv_dimension_t *d = s->dimension_list[i];
+    if(d){
+      u->dim_vals[0][i] = d->bracket[0];
+      u->dim_vals[1][i] = d->val;
+      u->dim_vals[2][i] = d->bracket[1];
+    }
+  }
+
+  // pass off panel population to panels
   for(j=0;j<s->panels;j++)
     if(s->panel_list[j])
-      _sushiv_panel_undo_log(s->panel_list[j], u+j);
+      _sushiv_panel_undo_log(s->panel_list[j], u->panels+j);
 }
 
 void _sushiv_undo_restore(sushiv_instance_t *s){
   int i;
-  
-  for(i=0;i<s->panels;i++){
-    sushiv_panel_undo_t *u = &s->private->undo_stack[s->private->undo_level][i];
-    
-    _sushiv_panel_undo_restore(s->panel_list[i],u);
-    plot_expose_request(PLOT(s->panel_list[i]->private->graph));
+  sushiv_instance_undo_t *u = s->private->undo_stack[s->private->undo_level];
+
+  // panels
+  for(i=0;i<s->panels;i++)
+    _sushiv_panel_undo_restore(s->panel_list[i],u->panels+i);
+
+  // dims 
+  for(i=0;i<s->dimensions;i++){
+    sushiv_dimension_t *d = s->dimension_list[i];
+    if(d){
+      sushiv_dimension_set_value(s, d->number, 0, u->dim_vals[0][i]);
+      sushiv_dimension_set_value(s, d->number, 1, u->dim_vals[1][i]);
+      sushiv_dimension_set_value(s, d->number, 2, u->dim_vals[2][i]);
+    }
   }
 }
 



More information about the commits mailing list