home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 344b.lha / plplot_v2.6 / drivers / aegis.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-01-27  |  4.7 KB  |  222 lines

  1. /* This file contains drivers for the HP7475A plotter */
  2.  
  3. #include "plplot.h"
  4. #include <stdio.h>
  5. #include <string.h>
  6.  
  7. #define AEGX       10000
  8. #define AEGY       10000
  9.  
  10. static FILE *OutDev;
  11. static PLINT select=0;
  12. static char FileName[80];
  13. static short *buffptr, bufflen;
  14. #define BSIZE  25
  15.  
  16. void aegissetup(xdpi, ydpi, xwid, ywid)
  17. PLINT xwid, ywid;
  18. PLFLT xdpi, ydpi;
  19. {
  20. }
  21.  
  22. void aegisselect(ori, name)
  23. PLINT ori;
  24. char *name;
  25. {
  26.    strncpy(FileName,name,sizeof(FileName)-1);
  27.    FileName[sizeof(FileName)-1] = '\0';
  28.    select = 1;
  29. }
  30.  
  31. /* Set up device specific stuff and initialize the device */
  32. void aegisinit()
  33. {
  34.    /* setpxl() sets the dots/mm in the x and y directions */
  35.    setpxl((PLFLT)39.37, (PLFLT)39.37);
  36.  
  37.    /* setphy() sets the device coordinates. These are integer */
  38.    /* values. Set up for landscape orientation (long axis of page in the */
  39.    /* x direction). Origin is in the lower left hand corner. */
  40.    setphy(0,AEGX,0,AEGY);
  41.  
  42.    /* Set default pen color using scol(color). */
  43.    /* Any default pen color can be used but a black pen is probably best. */
  44.    scol(1);
  45.  
  46.    /* Set default pen width using swid(width) */
  47.    swid(1);
  48.  
  49.    /* Set device interaction mode using smod(mode). Set mode to 0 for */
  50.    /* a noninteractive device, Unless you are writing your */
  51.    /* own Amiga screen driver mode should be 0. */
  52.    smod(0);
  53.  
  54.    bufflen = 2*BSIZE;
  55.    buffptr = (short *)malloc(sizeof(short)*bufflen);
  56.    if(buffptr == NULL)
  57.       plexit("Out of memory!");
  58.  
  59. }
  60.  
  61. /* Sets to text mode */
  62. void aegistext()
  63. {
  64. }
  65.  
  66. /* Sets to graphics mode */
  67. void aegisgraph()
  68. {
  69. }
  70.  
  71. static PLINT firstline;
  72. /* Clears the page */
  73. void aegisclear()
  74. {
  75.    void flushbuffer();
  76.  
  77.    /* Close the file */
  78.    if(!firstline) {
  79.       flushbuffer();
  80.    }
  81.    fclose(OutDev);
  82. }
  83.  
  84. static short xlast, ylast;
  85.  
  86. void aegispage()
  87. {
  88.    char line[80];
  89.    for(;;) {
  90.       if(!select) {
  91.          printf("Enter graphics file name. ");
  92.          fgets(line,sizeof(line),stdin);
  93.          if(sscanf(line,"%s",FileName)!=1)
  94.             continue;
  95.       }
  96.  
  97.       if (!(OutDev = fopen(FileName,"w"))) {
  98.          fprintf(stderr,"Can't open %s.\n",FileName);
  99.          select = 0;
  100.       }
  101.       else
  102.          break;
  103.    }
  104.    select = 0;
  105.    firstline = 1;
  106.    xlast = -10000; ylast = -10000;
  107.  
  108.    /* Write out header */
  109.    fprintf(OutDev,"81086 0.0 0.0 100.0 100.0 0 10.\n");
  110.    fprintf(OutDev,"\"%s\"\n-1\n",FileName);
  111. }
  112.  
  113. static int curwid;
  114. void aegiswidth(width)
  115. PLINT width;
  116. {
  117.    void flushbuffer();
  118.  
  119.    flushbuffer();
  120.    firstline = 1;
  121.  
  122.    if(width <= 1)
  123.       curwid = 0;
  124.    else if(width >= 4)
  125.       curwid = 3;
  126.    else
  127.       curwid = width-1;
  128. }
  129.  
  130. static int curcol;
  131. /* Change the pen color */
  132. void aegiscolor(color)
  133. PLINT color;
  134. {
  135.    void flushbuffer();
  136.  
  137.    flushbuffer();
  138.    firstline = 1;
  139.    /* Aegis pen 1 is the "paper" color */
  140.    if (color >= 2 && color <=15)
  141.       curcol = color;
  142.    else
  143.       curcol = 0;
  144. }
  145.  
  146. static short count, xmin, xmax, ymin, ymax;
  147.  
  148. /* Draws a line from (x1,y1) to (x2,y2) */
  149. void aegisline(x1,y1,x2,y2)
  150. PLINT x1,y1,x2,y2;
  151. {
  152.    short *tempptr;
  153.    void flushbuffer();
  154.  
  155.    /* If starting point of this line is the same as the ending point of */
  156.    /* the previous line then don't raise the pen. (This really speeds up */
  157.    /* plotting and reduces the size of the file. */
  158.    if(firstline) {
  159.       count = 0;
  160.       *(buffptr+count++) = x1;
  161.       *(buffptr+count++) = y1;
  162.       *(buffptr+count++) = x2;
  163.       *(buffptr+count++) = y2;
  164.       xmin = min(x1,x2); ymin = min(y1,y2);
  165.       xmax = max(x1,x2); ymax = max(y1,y2);
  166.       firstline = 0;
  167.    }
  168.    else if(x1 == xlast && y1 == ylast) {
  169.       if(count+2 >= bufflen) {
  170.          bufflen += 2*BSIZE;
  171.          tempptr = (short *)realloc((void *)buffptr,bufflen*sizeof(short));
  172.          if(tempptr == NULL){
  173.             free((void *)buffptr);
  174.             plexit("Out of memory!");
  175.          }
  176.          buffptr = tempptr;
  177.       }
  178.       *(buffptr+count++) = x2;
  179.       *(buffptr+count++) = y2;
  180.       xmin = min(x2,xmin); ymin = min(y2,ymin);
  181.       xmax = max(x2,xmax); ymax = max(y2,ymax);
  182.    }
  183.    else {
  184.       flushbuffer();
  185.       *(buffptr+count++) = x1;
  186.       *(buffptr+count++) = y1;
  187.       *(buffptr+count++) = x2;
  188.       *(buffptr+count++) = y2;
  189.       xmin = min(x1,x2); ymin = min(y1,y2);
  190.       xmax = max(x1,x2); ymax = max(y1,y2);
  191.    }
  192.  
  193.    xlast = x2;
  194.    ylast = y2;
  195. }
  196.  
  197. static void flushbuffer()
  198. {
  199.    short i=0;
  200.  
  201.    fprintf(OutDev,"1 52 %.2f %.2f",xmin/100.,ymin/100.);
  202.    fprintf(OutDev," %.2f %.2f",xmax/100.,ymax/100.);
  203.    fprintf(OutDev," %d 0 0 %d 0\n",curcol,curwid);
  204.    while(i<count) {
  205.      fprintf(OutDev," 1 %.2f %.2f\n",*(buffptr+i)/100.,*(buffptr+i+1)/100.);
  206.      i += 2;
  207.    }
  208.    fprintf(OutDev," 0\n");
  209.    count = 0;
  210. }
  211.  
  212. /* Cleanup and close file. */
  213. void aegistidy()
  214. {
  215.    flushbuffer();
  216.    free((VOID *)buffptr);
  217.    fclose(OutDev);
  218. }
  219.  
  220.  
  221.  
  222.