Google
 

Trailing-Edge - PDP-10 Archives - decuslib20-03 - decus/20-0078/libsim/figure.sim
There is 1 other file named figure.sim in the archive. Click here to see a list.
OPTIONS(/E);
CLASS figure;  COMMENT: Version 4, nov 1976, $ke Blomberg;

BEGIN

    TEXT t;   INTEGER cc;

    CHARACTER highx,lowx,highy,lowy,saved_mode,gmode,amode;
    REAL origin_x,origin_y,scale_x,scale_y,xmin,xmax,ymin,ymax;
    BOOLEAN sizecheck;
    

    PROCEDURE check_length(l); INTEGER l;
    BEGIN
	WHILE l > t.Length DO
	BEGIN TEXT new_t; new_t:-Blanks(2*t.Length);
	    new_t:=t; t:-new_t; t.Setpos(cc+1);
	END;
    END***CHECK_LENGTH***;



    PROCEDURE trans_to_plotchar(x,y); REAL x,y;
    BEGIN	INTEGER a,b,c;

	IF sizecheck THEN check_size(x,y);

	a:=Entier(origin_x+scale_x*x);
	b:=a//32; c:=a-32*b;
	highx:=Char(32+b); lowx:=Char(64+c);

	a:=Entier(origin_y+scale_y*y);
	b:=a//32; c:=a-32*b;
	highy:=Char(32+b); lowy:=Char(96+c);


    END***TRANS_TO_PLOTCHAR***;
    

    PROCEDURE check_size(x,y); real x,y;
    BEGIN BOOLEAN fatal;
	if x > xmax then xmax:=x;
	if x < xmin then xmin:=x;
	if y > ymax then ymax:=y;
	if y < ymin then ymin:=y;
    fatal:=    (origin_x+scale_x*xmin < -1055)  or
               (origin_x+scale_x*xmax > 3071) or
               (origin_y+scale_y*ymin < -1055)  or
               (origin_y+scale_y*ymax > 3071);
    IF fatal THEN
       BEGIN
       OUTTEXT("FATAL FIGURE ERROR"); outimage;
       OUTTEXT("CAN'T HANDLE COORDINATES OUTSIDE [-1055,3071]");
       OUTIMAGE;
       END;

    END***check_size***;


    BOOLEAN PROCEDURE On_screen;
    BEGIN
    on_screen:=(origin_x+scale_x*xmin >= 0)     and
               (origin_x+scale_x*xmax <= 1023)  and
               (origin_y+scale_y*ymin >= 0)     and
               (origin_y+scale_y*ymax <= 759);

    END***On_screen***;
    PROCEDURE checkon; sizecheck:=TRUE;

    PROCEDURE checkoff; sizecheck:=FALSE;
    

    PROCEDURE moveto(x,y); REAL x,y;
    BEGIN	trans_to_plotchar(x,y); check_length(cc+5); cc:=cc+5;
	t.Putchar(gmode);
	t.Putchar(highy); t.Putchar(lowy);
	t.Putchar(highx); t.Putchar(lowx);
    END***MOVETO***;



    PROCEDURE drawto(x,y); REAL x,y;
    BEGIN	trans_to_plotchar(x,y); check_length(cc+4); cc:=cc+4;
	t.Putchar(highy); t.Putchar(lowy);
	t.Putchar(highx); t.Putchar(lowx);
    END***DRAWTO***;



    PROCEDURE write(string); VALUE string; TEXT string;
    BEGIN	check_length(cc+1+string.Length); cc:=cc+1+string.Length;
	t.Putchar(amode); string.Setpos(1);
	WHILE string.More DO t.Putchar(string.Getchar);
    END***WRITE***;
    

    PROCEDURE plot;
    BEGIN	Sysout.Image:-Blanks(cc+1);
	Outtext(t.Sub(1,cc)); Outchar(amode); Breakoutimage;
	Sysout.Image:-Blanks(132);
    END***PLOT***;



    PROCEDURE savefig(ofile); VALUE ofile; TEXT ofile;
    BEGIN REF(Outfile) of; of:-NEW Outfile(ofile);
	of.Open(Blanks(5)); of.Outint(cc,5); of.Outimage;
	of.Image:-Blanks(cc); of.Outtext(t.Sub(1,cc));
	of.Outimage; of.Close;
    END***SAVEFIG***;



    PROCEDURE getfig(ifile); VALUE ifile; TEXT ifile;
    BEGIN INTEGER size;
	REF(Infile) ifi; ifi:-NEW Infile(ifile);
	ifi.Open(Blanks(5)); ifi.Inimage; size:=ifi.Inint;
	ifi.Image:-Blanks(size); ifi.Inimage; t:-ifi.Image;
	t.Setpos(size+1); cc:=size; ifi.Close;
    END***GETFIG***;
    

    PROCEDURE origin(ox,oy); REAL ox,oy;
    BEGIN	origin_x:=ox; origin_y:=oy;
    END***ORIGIN***;



    PROCEDURE scale(sx,sy); REAL sx,sy;
    BEGIN	scale_x:=sx; scale_y:=sy;
    END***SCALE***;



    PROCEDURE addfig(fig); REF (figure) fig;
    BEGIN
	check_length(cc+fig.cc);
	t.Sub(cc+1,fig.cc):=fig.t.Sub(1,fig.cc);
	cc:=cc+fig.cc; t.Setpos(cc+1);
    END***ADDFIG***;
    


    PROCEDURE sizefrom(fig); REF (figure) fig;
    BEGIN
        scale_x:=fig.scale_x;    scale_y:=fig.scale_y;
	origin_x:=fig.origin_x;  origin_y:=fig.origin_y;
    END***sizefrom***;
procedure recompute;
begin text oldt; character c,hx,lx,hy,ly;
integer oldcc,textstart,textlength;  real x,y;

oldt:-copy(t); oldcc:=cc; cc:=0; oldt.setpos(1); t.setpos(1);
xmax:=-1&+30; xmin:=1&+30; ymax:=xmax; ymin:=xmin;

while cc < oldcc do
begin c:=oldt.getchar;

if c=amode then begin textstart:=oldt.pos;
		while c\=gmode and oldt.pos <= oldcc do
		c:=oldt.getchar; textlength:=oldt.pos-1-textstart;
		write(oldt.sub(textstart,textlength));
		if c=gmode then oldt.setpos(oldt.pos-1);
		end

else if c=gmode then
	begin hy:=oldt.getchar; ly:=oldt.getchar;
	      hx:=oldt.getchar; lx:=oldt.getchar;
	x:=32*rank(hx)+rank(lx)-1088;
	y:=32*rank(hy)+rank(ly)-1120;   moveto(x,y);
	end

else begin hy:=c;
     ly:=oldt.getchar; hx:=oldt.getchar; lx:=oldt.getchar;
     x:=32*rank(hx)+rank(lx)-1088; y:=32*rank(hy)+rank(ly)-1120;
     drawto(x,y);
     end;
end;
end***recompute***;

Comment:     initial settings:                         ;

    t:-Blanks(25); cc:=0; t.Setpos(1);
    origin_x:=0; origin_y:=0; scale_x:=1; scale_y:=1;
    amode:=Char(31);  gmode:=Char(29);
    sizecheck:=FALSE;
    xmax:=-1&+30; xmin:=1&+30; ymax:=xmax; ymin:=xmin;

END***FIGURE***