/* tclsave.c */ /* * Vis5D system for visualizing five dimensional gridded data sets. * Copyright (C) 1990 - 2000 Bill Hibbard, Johan Kellum, Brian Paul, * Dave Santek, and Andre Battaiola. * * 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 2 of the License, or * (at your option) any later version. * * As a special exception to the terms of the GNU General Public * License, you are permitted to link Vis5D with (and distribute the * resulting source and executables) the LUI library (copyright by * Stellar Computer Inc. and licensed for distribution with Vis5D), * the McIDAS library, and/or the NetCDF library, where those * libraries are governed by the terms of their own licenses. * * 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. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */ #include "../config.h" /* * Tcl-based save and restore. */ #include #include #include "globals.h" #include "graphics.h" #include "gui.h" /* * Return the parameters which describe a colorbar curve. * If one or more color table entries were 'drawn' by the user, rather * than computed from the parameters, return 1. Return 0 if the user * has not drawn the curves. * Input: index - context index * graphic - one of: VIS5D_ISOSURF, VIS5D_CHSLICE, VIS5D_CVSLICE, * VIS5D_VOLUME, VIS5D_TRAJ or VIS5D_TOPO. * var - variable number if type isn't VIS5D_TOPO * Output: params - pointer to address of parameter array */ static int get_colorbar_params( int index, int graphic, int vindex, int var, float params[] ) { float *p; int i; unsigned int temptable[256], *table; int same; vis5d_get_color_table_params( index, graphic, vindex, var, &p ); for (i=0; i<7; i++) params[i] = p[i]; /* * This is tricky. Compare the graphic's color table to one computed * from its parameters. If they're different return 1, else return 0. * This is used by the SAVE function to determine if all the color * table entries have to be written or just the parameters which * describe the curves. */ vis5d_get_color_table_address( index, graphic, vindex, var, &table ); vis5d_color_table_recompute( temptable, 256, params, 1, 1 ); same = 1; for (i=0;i<255;i++) { if (table[i]!=temptable[i]) { same = 0; break; } } if (same) { return 0; } else { return 1; } } /* * Save current graphics and colors to the 'savefile' as a Tcl script. * Input: savefile - filename to save to. * Return: 0 for success, * VIS5D_BAD_VALUE if unable to open file * VIS5D_FAIL if error while writing file. */ int tcl_save( int index, char *savefile ) { FILE *f; int cyo, chowmany, cwhichones[VIS5D_MAX_CONTEXTS]; int var, i, k; int numvars; float r, g, b, a; char varname[20]; vis5d_get_num_of_ctxs_in_display( index, &chowmany, cwhichones); f = fopen(savefile,"w"); if (!f) { return VIS5D_BAD_VALUE; } /* Prolog */ fprintf(f,"#Vis5D 4.3 Tcl save file\n\n"); for ( cyo = 0; cyo < chowmany; cyo++){ int vindex = cwhichones[cyo]; vis5d_get_ctx_numvars( cwhichones[cyo], &numvars ); /* misc colors */ fprintf(f,"\n#Box color\n"); vis5d_get_color( index, VIS5D_BOX, 0, &r, &g, &b, &a ); fprintf(f,"vis5d_set_color $dtx VIS5D_BOX 0 %5.3f %5.3f %5.3f %5.3f\n", r,g,b,a ); fprintf(f,"\n#Light map color\n"); vis5d_get_color( index, VIS5D_LIGHT_MAP, 0, &r, &g, &b, &a ); fprintf(f,"vis5d_set_color $dtx VIS5D_LIGHT_MAP 0 %5.3f %5.3f %5.3f %5.3f\n", r,g,b,a ); fprintf(f,"\n#Dark map color\n"); vis5d_get_color( index, VIS5D_DARK_MAP, 0, &r, &g, &b, &a ); fprintf(f,"vis5d_set_color $dtx VIS5D_DARK_MAP 0 %5.3f %5.3f %5.3f %5.3f\n", r,g,b,a ); fprintf(f,"\n#Background color\n"); vis5d_get_color( index, VIS5D_BACKGROUND, 0, &r, &g, &b, &a ); fprintf(f, "vis5d_set_color $dtx VIS5D_BACKGROUND 0 %5.3f %5.3f %5.3f %5.3f\n", r,g,b,a ); /* Text labels */ fprintf(f,"\n#Text labels\n"); { int i = 1; int x, y; char label[1000]; while (vis5d_get_label( index, i, &x, &y, label )==0) { fprintf(f,"vis5d_make_label $dtx %d %d \"%s\"\n", x, y, label ); i++; } } /* View matrix */ fprintf(f,"\n#Viewing matrix\n"); { float mat[4][4]; int i, j; vis5d_get_matrix( index, mat ); fprintf(f,"vis5d_set_matrix $dtx {"); for (i=0;i<4;i++) { for (j=0;j<4;j++) { fprintf(f," %g", mat[i][j] ); } } fprintf(f," }\n"); } /* Camera */ fprintf(f,"\n#Camera\n"); { int perspec; float front, zoom; vis5d_get_camera( index, &perspec, &front, &zoom ); fprintf(f,"vis5d_set_camera $dtx %d %g %g\n", perspec, front, zoom ); } /* Cloned and computed physical variables */ fprintf(f,"\n#Cloned or computed variables\n"); for (var=0; var-1) { char colorvarname[20]; vis5d_get_ctx_var_name( colorvarowner, colorvar, colorvarname ); if (cyo == 0) { fprintf(f,"vis5d_set_isosurface_color_var_and_owner $ctx \"%s\" %d \"%s\"\n", varname, colorvarowner, colorvarname ); } else { fprintf(f,"vis5d_set_isosurface_color_var_and_owner %d \"%s\" %d \"%s\"\n", cwhichones[cyo], varname, colorvarowner, colorvarname ); } } /* command to recompute the isosurface */ if (cyo == 0) { fprintf(f,"vis5d_make_isosurface $ctx VIS5D_ALL_TIMES \"%s\" 0\n", varname ); } else { fprintf(f,"vis5d_make_isosurface %d VIS5D_ALL_TIMES \"%s\" 0\n", cwhichones[cyo], varname ); } } if (vis5d_enable_graphics(cwhichones[cyo],VIS5D_ISOSURF,var,VIS5D_GET)){ if (cyo == 0) { fprintf(f,"vis5d_enable_graphics $ctx VIS5D_ISOSURF %d VIS5D_ON\n", var); } else { fprintf(f,"vis5d_enable_graphics %d VIS5D_ISOSURF %d VIS5D_ON\n", cwhichones[cyo], var); } } /* WLH 10 Nov 98 */ else { if (cyo == 0) { fprintf(f,"vis5d_enable_graphics $ctx VIS5D_ISOSURF %d VIS5D_OFF\n", var); } else { fprintf(f,"vis5d_enable_graphics %d VIS5D_ISOSURF %d VIS5D_OFF\n", cwhichones[cyo], var); } } } /* Horizontal contour slices */ fprintf(f,"\n#Horizontal contour slices\n"); for (var=0;var -1 && current_vol > -1){ /* WLH 16 Nov 98 fprintf(f,"vis5d_set_volume_and_owner $dtx %d %d\n", current_vol_owner, current_vol); */ /* WLH 16 Nov 98 */ if (current_vol_owner == cwhichones[0]) { fprintf(f,"vis5d_set_volume_and_owner $dtx $ctx %d\n", current_vol); } else { fprintf(f,"vis5d_set_volume_and_owner $dtx %d %d\n", current_vol_owner, current_vol); } } else{ fprintf(f,"vis5d_set_volume_and_owner $dtx -1 -1\n"); } } /* Horizontal wind vector slices */ fprintf(f,"\n#Horizontal wind vector slices\n"); for (i=0;i=0) { char varname[20]; vis5d_get_ctx_var_name( colorvarowner, colorvar, varname ); fprintf(f,"vis5d_set_trajectory_color_var_and_owner $dtx %d %d \"%s\"\n", i, colorvarowner, varname ); } } /* TO HERE */ /* Isosurface color tables */ fprintf(f,"\n#Isosurface color tables\n"); for (var=0;var=0) { vis5d_get_ctx_var_name( index, var, varname ); k = get_colorbar_params( index, VIS5D_TOPO, vindex, var, params ); } else { int j; for (j=0; j<8; j++) params[j] = 0; strcpy( varname, "-1" ); k = 1; } if (vindex == cwhichones[0]) { fprintf(f,"vis5d_set_color_table_params $dtx VIS5D_TOPO $ctx"); } else { fprintf(f,"vis5d_set_color_table_params $dtx VIS5D_TOPO %d", vindex); } fprintf(f," \"%s\" %.3f %.3f %.3f %.3f\n", varname, params[0], params[1], params[2], params[3] ); if (k) { /* the color table can't be described by the parameters alone */ /* save each individual table entry */ vis5d_get_color_table_address( index, VIS5D_TOPO, vindex, var, &ctable ); for (i=0;i<256;i++) { if (vindex == cwhichones[0]) { fprintf(f,"vis5d_set_color_table_entry $dtx VIS5D_TOPO $ctx"); } else { fprintf(f,"vis5d_set_color_table_entry $dtx VIS5D_TOPO %d", vindex); } fprintf(f," \"%s\" %d %d %d %d %d\n", varname, i, UNPACK_RED(ctable[i]), UNPACK_GREEN(ctable[i]), UNPACK_BLUE(ctable[i]), UNPACK_ALPHA(ctable[i]) ); } fprintf(f,"\n"); } } } { int colorvar, colorvarowner; vis5d_get_topo_color_var( index, &colorvarowner, &colorvar ); fprintf(f, "\n"); fprintf(f, "vis5d_set_topo_color_var_and_owner $dtx %d %d\n", colorvarowner, colorvar ); } /* MJK 12.04.98 begin */ /* TODO */ /* if (vis5d_graphics_mode (index, VIS5D_BOX, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_BOX VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_CLOCK, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_CLOCK VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_MAP, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_MAP VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_TOPO, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_TOPO VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_LEGENDS, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_LEGENDS VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_PERSPECTIVE, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_PERSPECTIVE VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_CONTOUR_NUMBERS, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_CONTOUR_NUMBERS VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_GRID_COORDS, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_GRID_COORDS VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_PRETTY, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_PRETTY VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_INFO, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_INFO VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_PROBE, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_PROBE VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SOUND, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SOUND VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_CURSOR, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_CURSOR VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_ANIMRECORD, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_ANIMRECORD VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_TEXTURE, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_TEXTURE VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_DEPTHCUE, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_DEPTHCUE VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_JULIAN, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_JULIAN VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_BARBS, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_BARBS VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_THTA, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_THTA VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_THTE, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_THTE VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_W, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_W VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_TICKS, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_TICKS VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_MIXRAT, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_MIXRAT VIS5D_ON\n"); if (vis5d_graphics_mode (index, VIS5D_SND_TEMP, VIS5D_GET) == VIS5D_ON) fprintf (f, "vis5d_graphics_mode $ctx VIS5D_SND_TEMP VIS5D_ON\n"); */ fprintf(f, "\nvis5d_draw_frame %d\n", index ); fclose(f); return 0; }