/* pen.c ******************************************************************** * virtual plotter * Accept pen up, down commands and x,y coordinates. Make physical i/o * calls only when necessary: * 1) When pen is lifted after having been down, * 2) When calling routine requests by setting ptype to "DATA". * * Not a general purpose routine. Part of a hidden line algorithm is * implemented here. *****************************************/ #include "tdp.h" void pen(NewPenState,hpos,ptype,hinc,vcum) register short NewPenState,hpos,ptype; register short *vcum; { static short PenState = RESET, hstart = 0, hcur = -1; if (PenState == DOWN) { if (NewPenState == UP) { if (hstart != hcur) { Move(rp,hstart,TOPVERT-vcum[hstart]); if (PlotFile) fprintf(pfp,"PU %d %d;\n",1+hstart,1+TOPVERT-vcum[hstart]); if (To_mCAD) fprintf(mfp,"\n%d %d\n", hstart, vcum[hstart]); } hcur = hpos-hinc; Draw(rp, hcur, TOPVERT-vcum[hcur]); if (PlotFile) fprintf(pfp,"PD %d %d;\n", 1+hcur, 1+TOPVERT-vcum[hcur]); if (To_mCAD) fprintf(mfp,"%d %d\n*>\n", hcur, vcum[hcur]); hstart = hpos; } else if (ptype == DATA) { if (hstart != hcur) { Move(rp,hstart,TOPVERT-vcum[hstart]); if (PlotFile) fprintf(pfp,"PU %d %d;\n",1+hstart,1+TOPVERT-vcum[hstart]); if (To_mCAD) fprintf(mfp,"\n%d %d\n", hstart, vcum[hstart]); } Draw(rp, hpos, TOPVERT-vcum[hpos]); if (PlotFile) fprintf(pfp,"PD %d %d;\n", 1+hpos, 1+TOPVERT-vcum[hpos]); if (To_mCAD) fprintf(mfp,"%d %d\n", hpos, vcum[hpos]); hcur = hpos; hstart = hpos; } else if (NewPenState == RESET) hstart = hpos; } else if (NewPenState == DOWN) { if (ptype == INTERP) hstart = hpos-hinc; else if ((PenState != RESET) && (ptype == DATA)) { hcur = hpos-hinc; Move(rp, hcur, TOPVERT-vcum[hcur]); Draw(rp, hpos, TOPVERT-vcum[hpos]); if (PlotFile) { fprintf(pfp,"PU %d %d;\n", 1+hcur, 1+TOPVERT-vcum[hcur]); fprintf(pfp,"PD %d %d;\n", 1+hpos, 1+TOPVERT-vcum[hpos]); } if (To_mCAD) { fprintf(mfp,"\n%d %d\n", hcur, vcum[hcur]); fprintf(mfp,"%d %d\n", hpos, vcum[hpos]); } hstart = (hcur = hpos); } } else hstart = hpos; PenState = NewPenState; }