version 1.14, 2004/03/11 12:25:20 |
version 1.18, 2006/03/08 04:58:15 |
|
|
/* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.13 2004/03/11 05:16:11 takayama Exp $ */ |
/* $OpenXM: OpenXM_contrib2/asir2000/lib/glib,v 1.17 2006/03/03 10:36:18 takayama Exp $ */ |
/* $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. |
*/ |
*/ |
|
|
|
extern Cfep_loaded$ |
|
|
#define DO_NOT_START_SERVER_EXPLICITLY |
#define DO_NOT_START_SERVER_EXPLICITLY |
|
|
/* #define CLIP 1 */ |
/* #define CLIP 1 */ |
Line 36 def glib_ox_get_errors(P) { |
|
Line 37 def glib_ox_get_errors(P) { |
|
|
|
def reset_plot() { |
def reset_plot() { |
extern Glib_process; |
extern Glib_process; |
print(" Sending signal to ox_plot",0); |
if (!Cfep_loaded) { |
ox_reset(Glib_process); |
print(" Sending signal to ox_plot",0); |
print(" Done."); |
ox_reset(Glib_process); |
|
print(" Done."); |
|
} |
} |
} |
Glib_ps = 0$ |
Glib_ps = 0$ |
Glib_h = []$ |
Glib_h = []$ |
Line 54 Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffs |
|
Line 57 Glib_xmag = 1$ Glib_ymag=1$ Glib_xoffset=0$ Glib_yoffs |
|
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) { |
extern Glib_process; |
extern Glib_process; |
if (P < 0) P=open_canvas(S); /* BUG, get process No. */ |
/* print("open_Canvas: ",0);print(S); */ |
else open_canvas(P,S); |
if (!Cfep_loaded) { |
Glib_process = P; |
if (P < 0) P=open_canvas(S); /* BUG, get process No. */ |
R = ox_pop_cmo(P); |
else open_canvas(P,S); |
/* |
Glib_process = P; |
if (glib_ox_get_errors(P) == []) { |
|
R = ox_pop_cmo(P); |
R = ox_pop_cmo(P); |
|
/* |
|
if (glib_ox_get_errors(P) == []) { |
|
R = ox_pop_cmo(P); |
|
}else{ |
|
debug; |
|
} |
|
*/ |
}else{ |
}else{ |
debug; |
R=cfep.open_canvas(S); |
} |
} |
*/ |
|
return(R); |
return(R); |
} |
} |
|
|
Line 82 def glib_open() { |
|
Line 95 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, |
Glib_server_started, Glib_process$ |
Glib_server_started, Glib_process$ |
|
if (!Cfep_loaded) return glib_openx11(); |
|
else { |
|
Glib_canvas = open_Canvas(-1,[Glib_canvas_x,Glib_canvas_y])$ |
|
Glib_server_started = 1$ |
|
return(Glib_canvas); |
|
} |
|
} |
|
def glib_openx11() { |
|
extern Glib_canvas_x, Glib_canvas_y, |
|
Glib_process, Glib_canvas, |
|
Glib_server_started, Glib_process$ |
#ifndef DO_NOT_START_SERVER_EXPLICITLY |
#ifndef DO_NOT_START_SERVER_EXPLICITLY |
if (type(Glib_server_started) == 0) { |
if (type(Glib_server_started) == 0) { |
Glib_process = ox_launch_nox(0,"ox_plot")$ |
Glib_process = ox_launch_nox(0,"ox_plot")$ |
register_handler(reset_plot); |
register_handler(reset_plot); |
Glib_server_started = 1$ |
Glib_server_started = 1$ |
Line 120 def glib_check_strict() { |
|
Line 144 def glib_check_strict() { |
|
if (Glib_canvas < 0) { |
if (Glib_canvas < 0) { |
glib_open(); |
glib_open(); |
} |
} |
|
if (Cfep_loaded) return ; |
E = glib_ox_get_errors(Glib_process); |
E = glib_ox_get_errors(Glib_process); |
if (E != []) { |
if (E != []) { |
ox_pops(Glib_process,200); |
ox_pops(Glib_process,200); |
Line 135 def glib_check_strict() { |
|
Line 160 def glib_check_strict() { |
|
def glib_clear() { |
def glib_clear() { |
extern Glib_process, Glib_canvas; |
extern Glib_process, Glib_canvas; |
if (Glib_canvas < 0) glib_open(); |
if (Glib_canvas < 0) glib_open(); |
clear_canvas(Glib_process,Glib_canvas); |
if (!Cfep_loaded) clear_canvas(Glib_process,Glib_canvas); |
} |
} |
|
|
/*&usage begin: glib_window(Xmin,Ymin,Xmax,Ymax) |
/*&usage begin: glib_window(Xmin,Ymin,Xmax,Ymax) |
Line 196 def glib_putpixel(X,Y) { |
|
Line 221 def glib_putpixel(X,Y) { |
|
Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
} |
} |
if ( type(C) != -1 ) { |
if ( type(C) != -1 ) { |
draw_obj(Glib_process,Glib_canvas,Pos,C); |
if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos,C); |
|
else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,C); |
if (Glib_ps) glib_history(["putpixel",Pos2,C]); |
if (Glib_ps) glib_history(["putpixel",Pos2,C]); |
}else{ |
}else{ |
draw_obj(Glib_process,Glib_canvas,Pos); |
if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos); |
|
else cfep.draw_obj(Glib_process,Glib_canvas,Pos); |
if (Glib_ps) glib_history(["putpixel",Pos2,0]); |
if (Glib_ps) glib_history(["putpixel",Pos2,0]); |
} |
} |
} |
} |
|
|
glib_floor(X1),Glib_canvas_y-glib_floor(Y1)]; |
glib_floor(X1),Glib_canvas_y-glib_floor(Y1)]; |
} |
} |
if ( type(Color) != -1 ) { |
if ( type(Color) != -1 ) { |
draw_obj(Glib_process,Glib_canvas,Pos,Color); |
if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos,Color); |
|
else cfep.draw_obj2(Glib_process,Glib_canvas,Pos,Color); |
if (Glib_ps) glib_history(["line",Pos2,Color]); |
if (Glib_ps) glib_history(["line",Pos2,Color]); |
}else{ |
}else{ |
draw_obj(Glib_process,Glib_canvas,Pos); |
if (!Cfep_loaded) draw_obj(Glib_process,Glib_canvas,Pos); |
|
else cfep.draw_obj(Glib_process,Glib_canvas,Pos); |
if (Glib_ps) glib_history(["line",Pos2,0]); |
if (Glib_ps) glib_history(["line",Pos2,0]); |
} |
} |
} |
} |
Line 349 def glib_print(X,Y,Text) { |
|
Line 378 def glib_print(X,Y,Text) { |
|
Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
Glib_canvas_y-glib_floor(Glib_ymag*(Y+Glib_yoffset))]; |
} |
} |
if ( type(C) != -1 ) { |
if ( type(C) != -1 ) { |
draw_string(Glib_process,Glib_canvas,Pos,Text,C); |
if (!Cfep_loaded) draw_string(Glib_process,Glib_canvas,Pos,Text,C); |
|
else cfep.draw_string2(Glib_process,Glib_canvas,Pos,Text,C); |
if (Glib_ps) glib_history(["print",Pos2,Text,C]); |
if (Glib_ps) glib_history(["print",Pos2,Text,C]); |
}else{ |
}else{ |
draw_string(Glib_process,Glib_canvas,Pos,Text); |
if (!Cfep_loaded) draw_string(Glib_process,Glib_canvas,Pos,Text); |
|
else cfep.draw_string(Glib_process,Glib_canvas,Pos,Text); |
if (Glib_ps) glib_history(["print",Pos2,Text,0]); |
if (Glib_ps) glib_history(["print",Pos2,Text,0]); |
} |
} |
} |
} |
Line 371 def glib_history(L) { |
|
Line 402 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 381 def glib_tops() { |
|
Line 415 def glib_tops() { |
|
return glib_ps(Glib_h); |
return glib_ps(Glib_h); |
} |
} |
def glib_ps(L) { |
def glib_ps(L) { |
|
extern Glib_ps_sx; |
|
extern Glib_ps_sy; |
PS = string_to_tb(""); |
PS = string_to_tb(""); |
Prev_color = 0; |
Prev_color = 0; |
/* Prolog */ |
/* Prolog */ |
write_to_tb("%%!PS-Adobe-1.0\n",PS); |
write_to_tb("%%!PS-Adobe-1.0\n",PS); |
write_to_tb("%%BoundingBox: 0 0 " + |
write_to_tb("%%BoundingBox: 0 0 " + |
rtostr(Glib_canvas_x) + " " + rtostr(Glib_canvas_y) + "\n",PS); |
rtostr(xxx(Glib_canvas_x)) + " " + rtostr(yyy(Glib_canvas_y)) + "\n",PS); |
write_to_tb("%%Creator: This is generated by ifplot\n",PS); |
write_to_tb("%%Creator: This is generated by ifplot\n",PS); |
write_to_tb("%%Title: ifplot\n",PS); |
write_to_tb("%%Title: ifplot\n",PS); |
write_to_tb("%%EndComments: \n",PS); |
write_to_tb("%%EndComments: \n",PS); |
Line 410 def glib_ps(L) { |
|
Line 446 def glib_ps(L) { |
|
rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n",PS); |
rtostr(deval(iand(Prev_color,0xff)/256)) + " setrgbcolor \n",PS); |
} |
} |
if (C[0] == "putpixel") { |
if (C[0] == "putpixel") { |
write_to_tb(rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " ifplot_putpixel \n",PS); |
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") { |
write_to_tb(" newpath ",PS); |
write_to_tb(" newpath ",PS); |
write_to_tb(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",PS); |
rtostr(xxx(C[1][2])) + " " + rtostr(yyy(C[1][3])) + " lineto stroke \n",PS); |
} |
} |
if (C[0] == "print") { |
if (C[0] == "print") { |
write_to_tb("/Times-Roman findfont 10 scalefont setfont \n",PS); |
write_to_tb("/Times-Roman findfont 10 scalefont setfont \n",PS); |
write_to_tb(rtostr(C[1][0]) + " " + rtostr(C[1][1]) + " moveto ",PS); |
write_to_tb(rtostr(xxx(C[1][0])) + " " + rtostr(yyy(C[1][1])) + " moveto ",PS); |
write_to_tb("(" + C[2] + ") show \n",PS); |
write_to_tb("(" + C[2] + ") show \n",PS); |
} |
} |
} |
} |
Line 434 def glib_ps(L) { |
|
Line 470 def glib_ps(L) { |
|
/*&usage begin: glib_ps_form(S) |
/*&usage begin: glib_ps_form(S) |
It returns the PS code generated by executing {S} |
It returns the PS code generated by executing {S} |
(experimental). |
(experimental). |
BUG. Only one function call is allowed as an argument. |
|
example: glib_ps_form(quote( glib_line(0,0,100,100) )); |
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 |
ref: glib_tops |
end: */ |
end: */ |
|
/* Todo. Change the canvas size. */ |
def glib_ps_form(F) { |
def glib_ps_form(F) { |
extern Glib_h; |
extern Glib_h; |
extern Glib_ps; |
extern Glib_ps; |
Line 445 def glib_ps_form(F) { |
|
Line 482 def glib_ps_form(F) { |
|
P = Glib_ps; /* push Glib_ps */ |
P = Glib_ps; /* push Glib_ps */ |
|
|
Glib_ps=1; Glib_h = []; |
Glib_ps=1; Glib_h = []; |
|
if (type(F) != 17) { |
|
return "Error: argument should be quote(...)."; |
|
} |
eval_quote(F); |
eval_quote(F); |
/* bug. eval_str causes seg fault for ccurve.rr main(8) */ |
/* bug. eval_str causes seg fault for ccurve.rr main(8) */ |
R = glib_tops(); |
R = glib_tops(); |
|
|
def glib_plot(F) { |
def glib_plot(F) { |
Opt = getopt(); |
Opt = getopt(); |
taka_glib_plot(F,Opt); |
taka_glib_plot(F,Opt); |
|
} |
|
|
|
/*&usage begin: glib_flush(); |
|
Flush the output. |
|
(Cfep only. It also set initGL to 1.). |
|
end: */ |
|
def glib_flush() { |
|
extern Glib_canvas; |
|
if (Glib_canvas < 0) glib_open(); |
|
if (Cfep_loaded) cfep.draw_flush(Glib_canvas); |
|
} |
|
/*&usage begin: glib_set_pixel_size(P) |
|
Set the size of putpixel to P. 1.0 is the default. |
|
(cfep only). |
|
end: */ |
|
def glib_set_pixel_size(X) { |
|
extern Glib_canvas; |
|
if (Glib_canvas < 0) glib_open(); |
|
if (!Cfep_loaded) /*Not implemented.*/ ; |
|
else cfep.glib_set_pixel_size(X); |
|
} |
|
/*&usage begin: glib_clear() |
|
Clear the screen. |
|
(cfep only). |
|
end: */ |
|
def glib_clear() { |
|
extern Glib_canvas; |
|
if (Glib_canvas < 0) glib_open(); |
|
if (!Cfep_loaded) /*Not implemented.*/ ; |
|
else cfep.glib_clear(); |
|
} |
|
/*&usage begin: glib_remove_last() |
|
Remove the last object. glib_flush() should also be called to remove |
|
the last object. |
|
(cfep only). |
|
end: */ |
|
def glib_remove_last() { |
|
extern Glib_canvas; |
|
if (Glib_canvas < 0) glib_open(); |
|
if (!Cfep_loaded) /*Not implemented.*/ ; |
|
else cfep.glib_remove_last(); |
} |
} |
|
|
end$ |
end$ |