=================================================================== RCS file: /home/cvs/OpenXM_contrib/gnuplot/term/Attic/tkcanvas.trm,v retrieving revision 1.1.1.1 retrieving revision 1.1.1.2 diff -u -p -r1.1.1.1 -r1.1.1.2 --- OpenXM_contrib/gnuplot/term/Attic/tkcanvas.trm 2000/01/09 17:01:16 1.1.1.1 +++ OpenXM_contrib/gnuplot/term/Attic/tkcanvas.trm 2000/01/22 14:16:30 1.1.1.2 @@ -1,5 +1,5 @@ /* - * $Id: tkcanvas.trm,v 1.1.1.1 2000/01/09 17:01:16 maekawa Exp $ + * $Id: tkcanvas.trm,v 1.1.1.2 2000/01/22 14:16:30 maekawa Exp $ * */ @@ -57,6 +57,21 @@ * adapted to the new terminal layout by Alex Woo (Sept. 1996) */ +/* + * extended interactive Tk/Tcl capabilities + * Thomas Sefzick, March 1999, t.sefzick@fz-juelich.de + * + * added the perltk.trm code written by Slaven Rezic , + * the variable 'tk_perl' switches between tcl/tk and perltk code. + * 'linewidth' and 'justify text' added, ends of plotted lines are now rounded. + * if 'perltk' is chosen, perl code is produced, otherwise tcl code. + * Thomas Sefzick, May 1999, t.sefzick@fz-juelich.de + * + * scale plot to fit into the actual size of the canvas as reported by + * the window manager (the canvas itself doesn't report its real size). + * Matt Willis, October 1999, mattbwillis@my-deja.com + */ + #include "driver.h" #ifdef TERM_REGISTER @@ -64,6 +79,7 @@ register_term(tkcanvas) #endif #ifdef TERM_PROTO +TERM_PUBLIC void TK_options __PROTO((void)); TERM_PUBLIC void TK_init __PROTO((void)); TERM_PUBLIC void TK_graphics __PROTO((void)); TERM_PUBLIC void TK_text __PROTO((void)); @@ -72,6 +88,9 @@ TERM_PUBLIC void TK_move __PROTO((unsigned int x, unsi TERM_PUBLIC void TK_vector __PROTO((unsigned int x, unsigned int y)); TERM_PUBLIC void TK_put_text __PROTO((unsigned int x, unsigned int y, char *str)); TERM_PUBLIC void TK_reset __PROTO((void)); +TERM_PUBLIC int TK_justify_text __PROTO((enum JUSTIFY)); +TERM_PUBLIC int TK_set_font __PROTO((char *font)); +TERM_PUBLIC void TK_linewidth __PROTO((double linewidth)); #define TK_XMAX 1000 #define TK_YMAX 1000 @@ -88,89 +107,474 @@ TERM_PUBLIC void TK_reset __PROTO((void)); #ifndef TERM_PROTO_ONLY #ifdef TERM_BODY -static int tk_angle = 0; +/* plot2d.c */ +extern double min_array[], max_array[], base_array[], log_base_array[]; +extern TBOOLEAN log_array[]; +/* graphics.c */ +extern int xleft, xright, ybot, ytop; +extern TBOOLEAN is_3d_plot; + +/* static int tk_angle = 0; unused, for now */ static int tk_lastx; static int tk_lasty; static int tk_color = 0; -static char *tk_colors[] = { "black", "gray", "red", "blue", "green", "brown", "magenta", "cyan" }; +static char tk_anchor[7] = "w"; +static double tk_linewidth = 1.0; +static int tk_perl = 0; +static int tk_interactive = 0; +static char *tk_colors[] = { + "black", "gray", "red", "blue", "green", "brown", "magenta", "cyan" +}; -TERM_PUBLIC void TK_init() +TERM_PUBLIC void +TK_options() { - fputs("\ -proc gnuplot can {\n\ -$can delete all\n\ -set cmx [lindex [$can configure -width] 4]\n\ -set cmy [lindex [$can configure -height] 4]\n", - gpoutfile); + tk_perl = 0; + tk_interactive = 0; - tk_lastx = tk_lasty = tk_color = 0; + if (!END_OF_COMMAND) { + if (almost_equals(c_token, "p$erltk")) { + tk_perl = 1; + c_token++; + } + if (almost_equals(c_token, "i$nteractive")) { + tk_interactive = 1; + c_token++; + } + } + + sprintf(term_options, "%s %s", + tk_perl ? "perltk" : "", + tk_interactive ? "interactive" : ""); } +TERM_PUBLIC void +TK_init() +{ +} -TERM_PUBLIC void TK_graphics() +TERM_PUBLIC void +TK_graphics() { + /* + * the resulting tcl or perl code takes the actual width and height + * of the defined canvas and scales the plot to fit. + * => NOTE: this makes 'set size' useless !!! + * unless the original width and height is taken into account + * by some tcl or perl code, that's why the 'gnuplot_plotarea' and + * 'gnuplot_axisranges' procedures are supplied. + */ + if (tk_perl) { + fputs("\ +sub gnuplot {\n\ +my($can) = @_;\n\ +$can->delete('all');\n\ +my $cmx = ($can->configure(-width))[4];\n\ +my $cmy = ($can->configure(-height))[4];\n\ +my $cmx = $can->width - 2 * $can->cget(-border);\n\ +if ($cmx <= 1) {\n$cmx = ($can->cget(-width));\n}\n\ +my $cmy = $can->height - 2 * $can->cget(-border);\n\ +if ($cmy <= 1) {\n$cmy = ($can->cget(-height));\n}\n", + gpoutfile); + } else { + fputs("\ +proc gnuplot can {\n\ +$can delete all\n\ +set cmx [expr [winfo width $can]-2*[$can cget -border]]\n\ +if {$cmx <= 1} {set cmx [$can cget -width]}\n\ +set cmy [expr [winfo height $can]-2*[$can cget -border]]\n\ +if {$cmy <= 1} {set cmy [$can cget -height]}\n", + gpoutfile); + } + tk_lastx = tk_lasty = tk_color = 0; } - -TERM_PUBLIC void TK_reset() +TERM_PUBLIC void +TK_reset() { } -TERM_PUBLIC void TK_linetype(linetype) +TERM_PUBLIC void +TK_linetype(linetype) int linetype; { tk_color = (linetype + 2) & 7; } -TERM_PUBLIC void TK_move(x, y) +TERM_PUBLIC void +TK_linewidth(linewidth) +double linewidth; +{ + tk_linewidth = linewidth; +} + +TERM_PUBLIC void +TK_move(x, y) unsigned int x, y; { tk_lastx = x; tk_lasty = 1000 - y; } +#define TK_REAL_VALUE(value,axis) \ + (log_array[axis])\ + ?pow(base_array[axis],min_array[axis]+value*(max_array[axis]-min_array[axis]))\ + :min_array[axis]+value*(max_array[axis]-min_array[axis]) -TERM_PUBLIC void TK_vector(x, y) +#define TK_X_VALUE(value) \ + (double)(value-xleft)/(double)(xright-xleft) + +#define TK_Y_VALUE(value) \ + (double)((TK_YMAX-value)-ybot)/(double)(ytop-ybot) + +TERM_PUBLIC void +TK_vector(x, y) unsigned int x, y; { + /* + * this is the 1st part of the wrapper around the 'create line' command + * used to bind some actions to a line segment: + * bind { + * normal create line command + * } gnuplot_xy(some coordinates) + */ + if (tk_interactive && !is_3d_plot) { + if (tk_perl) + fprintf(gpoutfile, "$can->bind("); + else + fprintf(gpoutfile, "$can bind [\n"); + } + /* + * end of 1st part of wrapper + */ y = 1000 - y; - fprintf(gpoutfile, - "$can create line [expr $cmx * %d /1000] [expr $cmy * %d /1000] [expr $cmx * %d /1000] [expr $cmy * %d /1000] -fill %s\n", - tk_lastx, tk_lasty, x, y, tk_colors[tk_color]); + /* + * here is the basic well-known command for plotting a line segment + */ + if (tk_perl) { + fprintf(gpoutfile,"\ +$can->createLine(\ +$cmx * %d / 1000, \ +$cmy * %d / 1000, \ +$cmx * %d / 1000, \ +$cmy * %d / 1000, -fill => q{%s}, -width => %f, -capstyle => q{round})", + tk_lastx, tk_lasty, x, y, tk_colors[tk_color], tk_linewidth); + } else { + fprintf(gpoutfile,"\ +$can create line \ +[expr $cmx * %d /1000] \ +[expr $cmy * %d /1000] \ +[expr $cmx * %d /1000] \ +[expr $cmy * %d /1000] -fill %s -width %f -capstyle round\n", + tk_lastx, tk_lasty, x, y, tk_colors[tk_color], tk_linewidth); + } + + /* + * this is the 2nd part of the wrapper around the 'create line' + * command, it generates a mechanism which calls 'gnuplot_xy' for + * the line segment pointed to by the mouse cursor when a mouse + * button is pressed + */ + if (tk_interactive && !is_3d_plot) { + if (tk_perl) { + /* Ev('W') not needed here, supplied anyhow, WHY ??? */ + fprintf(gpoutfile,"\ +, '