| version 1.11, 2002/09/10 06:18:46 |
version 1.16, 2004/03/14 12:56:47 |
|
|
| /* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.10 2002/08/08 08:56:31 takayama Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.15 2004/03/11 21:59:36 takayama Exp $ */ |
| /* $Id$ */ |
/* $Id$ */ |
| |
|
| /* BUG: this library has not yet been adapted to the new automatic launcher |
/* BUG: this library has not yet been adapted to the new automatic launcher |
| of ox_plot. 2002, Aug, 4. Do not load glib more than twice. |
of ox_plot. 2002, Aug, 4. Do not load glib more than twice. |
| */ |
*/ |
| |
|
| |
#define DO_NOT_START_SERVER_EXPLICITLY |
| |
|
| /* #define CLIP 1 */ |
/* #define CLIP 1 */ |
| /* #define DEBUG 1 */ |
/* #define DEBUG 1 */ |
| #define LIST 4 |
#define LIST 4 |
| Line 45 Glib_canvas_y = 400$ |
|
| Line 47 Glib_canvas_y = 400$ |
|
| Glib_xmin=0$ Glib_xmax=Glib_canvas_x$ |
Glib_xmin=0$ Glib_xmax=Glib_canvas_x$ |
| Glib_ymin=0$ Glib_ymax=Glib_canvas_y$ |
Glib_ymin=0$ Glib_ymax=Glib_canvas_y$ |
| Glib_math_coordinate=0$ |
Glib_math_coordinate=0$ |
| #define START_SERVER \ |
|
| extern Glib_server_started, Glib_process$ \ |
|
| if (type(Glib_server_started) == 0) { \ |
|
| Glib_process = ox_launch_nox(0,"ox_plot")$ \ |
|
| register_handler(reset_plot); \ |
|
| Glib_server_started = 1$ \ |
|
| }$ |
|
| |
|
| |
|
| Glib_canvas = -1$ |
Glib_canvas = -1$ |
| Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffset=0$ |
Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffset=0$ |
| Glib_safe_mode = 2 $ |
Glib_safe_mode = 2 $ |
| Glib_counter = 100$ |
Glib_counter = 100$ |
| |
|
| |
extern Glib_ps_sx$ |
| |
extern Glib_ps_sy$ |
| |
Glib_ps_sx=2$ /* mag=1/2 for PS picture. cf. glib_ps_form, glib_tops */ |
| |
Glib_ps_sy=2$ /* mag=1/2 for PS picture */ |
| |
|
| def open_Canvas(P,S) { |
def open_Canvas(P,S) { |
| open_canvas(P,S); |
extern Glib_process; |
| |
if (P < 0) P=open_canvas(S); /* BUG, get process No. */ |
| |
else open_canvas(P,S); |
| |
Glib_process = P; |
| R = ox_pop_cmo(P); |
R = ox_pop_cmo(P); |
| /* |
/* |
| if (glib_ox_get_errors(P) == []) { |
if (glib_ox_get_errors(P) == []) { |
|
|
| |
|
| def glib_open() { |
def glib_open() { |
| extern Glib_canvas_x, Glib_canvas_y, |
extern Glib_canvas_x, Glib_canvas_y, |
| Glib_process, Glib_canvas; |
Glib_process, Glib_canvas, |
| START_SERVER |
Glib_server_started, Glib_process$ |
| |
#ifndef DO_NOT_START_SERVER_EXPLICITLY |
| |
if (type(Glib_server_started) == 0) { |
| |
Glib_process = ox_launch_nox(0,"ox_plot")$ |
| |
register_handler(reset_plot); |
| |
Glib_server_started = 1$ |
| |
}$ |
| Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$ |
Glib_canvas = open_Canvas(Glib_process,[Glib_canvas_x,Glib_canvas_y])$ |
| |
#else |
| |
Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$ |
| |
register_handler(reset_plot); |
| |
Glib_server_started = 1$ |
| |
#endif |
| glib_check_strict(); |
glib_check_strict(); |
| return(Glib_canvas); |
return(Glib_canvas); |
| } |
} |
| Line 361 def glib_history(L) { |
|
| Line 376 def glib_history(L) { |
|
| return 0; |
return 0; |
| } |
} |
| |
|
| |
#define xxx(x) idiv(x,Glib_ps_sx) |
| |
#define yyy(y) idiv(y,Glib_ps_sy) |
| |
|
| /*&usage begin: glib_tops() |
/*&usage begin: glib_tops() |
| If Glib_ps is set to 1, |
If Glib_ps is set to 1, |
| it returns a postscript program to draw the picture on the canvas. |
it returns a postscript program to draw the picture on the canvas. |
| Line 371 def glib_tops() { |
|
| Line 389 def glib_tops() { |
|
| return glib_ps(Glib_h); |
return glib_ps(Glib_h); |
| } |
} |
| def glib_ps(L) { |
def glib_ps(L) { |
| PS = ""; |
extern Glib_ps_sx; |
| |
extern Glib_ps_sy; |
| |
PS = string_to_tb(""); |
| Prev_color = 0; |
Prev_color = 0; |
| /* Prolog */ |
/* Prolog */ |
| PS += "%%!PS-Adobe-1.0\n"; |
write_to_tb("%%!PS-Adobe-1.0\n",PS); |
| PS += "%%BoundingBox: 0 0 " + |
write_to_tb("%%BoundingBox: 0 0 " + |
| rtostr(Glib_canvas_x) + " " + rtostr(Glib_canvas_y) + "\n"; |
rtostr(xxx(Glib_canvas_x)) + " " + rtostr(yyy(Glib_canvas_y)) + "\n",PS); |
| PS += "%%Creator: This is generated by ifplot\n"; |
write_to_tb("%%Creator: This is generated by ifplot\n",PS); |
| PS += "%%Title: ifplot\n"; |
write_to_tb("%%Title: ifplot\n",PS); |
| PS += "%%EndComments: \n"; |
write_to_tb("%%EndComments: \n",PS); |
| PS += "0.1 setlinewidth \n"; |
write_to_tb("0.1 setlinewidth \n",PS); |
| PS += "2 setlinecap \n"; |
write_to_tb("2 setlinecap \n",PS); |
| PS += "2 setlinejoin \n"; |
write_to_tb("2 setlinejoin \n",PS); |
| PS += "/ifplot_putpixel { \n"; |
write_to_tb("/ifplot_putpixel { \n",PS); |
| PS += " /yyy 2 1 roll def /xxx 2 1 roll def \n"; |
write_to_tb(" /yyy 2 1 roll def /xxx 2 1 roll def \n",PS); |
| PS += " gsave newpath xxx yyy .5 0 360 arc \n"; |
write_to_tb(" gsave newpath xxx yyy .5 0 360 arc \n",PS); |
| PS += " fill grestore \n"; |
write_to_tb(" fill grestore \n",PS); |
| PS += "} def \n"; |
write_to_tb("} def \n",PS); |
| |
|
| L = reverse(L); |
L = reverse(L); |
| N = length(L); |
N = length(L); |
| Line 395 def glib_ps(L) { |
|
| Line 415 def glib_ps(L) { |
|
| C = L[I]; |
C = L[I]; |
| if (C[length(C)-1] != Prev_color) { |
if (C[length(C)-1] != Prev_color) { |
| Prev_color = C[length(C)-1]; |
Prev_color = C[length(C)-1]; |
| PS += rtostr(deval(ishift(Prev_color,16)/256)) + " " + |
write_to_tb(rtostr(deval(ishift(Prev_color,16)/256)) + " " + |
| rtostr(deval(iand(ishift(Prev_color,8),0xff)/256)) + " " + |
rtostr(deval(iand(ishift(Prev_color,8),0xff)/256)) + " " + |
| rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n"; |
rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n",PS); |
| } |
} |
| if (C[0] == "putpixel") { |
if (C[0] == "putpixel") { |
| PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " ifplot_putpixel \n"; |
write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " ifplot_putpixel \n",PS); |
| } |
} |
| if (C[0] == "line") { |
if (C[0] == "line") { |
| PS += " newpath "; |
write_to_tb(" newpath ",PS); |
| PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " moveto " + |
write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto " + |
| rtostr(C[1][2]) + " " + rtostr(C[1][3]) + " lineto stroke \n"; |
rtostr(xxx(C[1][2])) + " " + rtostr(yyy(C[1][3])) + " lineto stroke \n",PS); |
| } |
} |
| if (C[0] == "print") { |
if (C[0] == "print") { |
| PS += "/Times-Roman findfont 10 scalefont setfont \n"; |
write_to_tb("/Times-Roman findfont 10 scalefont setfont \n",PS); |
| PS += rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " moveto "; |
write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto ",PS); |
| PS += "(" + C[2] + ") show \n"; |
write_to_tb("(" + C[2] + ") show \n",PS); |
| } |
} |
| } |
} |
| |
|
| /* Epilog */ |
/* Epilog */ |
| PS += "0 0 0 setrgbcolor \n"; |
write_to_tb("0 0 0 setrgbcolor \n",PS); |
| PS += "showpage \n"; |
write_to_tb("showpage \n",PS); |
| |
|
| return PS; |
return tb_to_string(PS); |
| |
} |
| |
|
| |
/*&usage begin: glib_ps_form(S) |
| |
It returns the PS code generated by executing {S} |
| |
(experimental). |
| |
example: glib_ps_form(quote( glib_line(0,0,100,100) )); |
| |
example: glib_ps_form(quote([glib_line(0,0,100,100),glib_line(100,0,0,100)])); |
| |
ref: glib_tops |
| |
end: */ |
| |
/* Todo. Change the canvas size. */ |
| |
def glib_ps_form(F) { |
| |
extern Glib_h; |
| |
extern Glib_ps; |
| |
H = Glib_h; /* push Glib_h */ |
| |
P = Glib_ps; /* push Glib_ps */ |
| |
|
| |
Glib_ps=1; Glib_h = []; |
| |
if (type(F) != 17) { |
| |
return "Error: argument should be quote(...)."; |
| |
} |
| |
eval_quote(F); |
| |
/* bug. eval_str causes seg fault for ccurve.rr main(8) */ |
| |
R = glib_tops(); |
| |
Glib_h = H; /* pop Glib_h */ |
| |
Glib_ps = P; /* pop Glib_ps */ |
| |
return R; |
| } |
} |
| |
|
| /*&usage begin: glib_plot(F) |
/*&usage begin: glib_plot(F) |