Back to index

radiance  4R0+20100331
plot.c
Go to the documentation of this file.
00001 #ifndef lint
00002 static const char    RCSid[] = "$Id: plot.c,v 1.3 2003/11/15 02:13:37 schorsch Exp $";
00003 #endif
00004 /*
00005  *  Plotting routines for meta-files
00006  */
00007 
00008 
00009 #include  "rtio.h"
00010 #include  "meta.h"
00011 #include  "plot.h"
00012 
00013 
00014 int  pati[4] = {0, 1, 2, 3};       /* pattern indices */
00015 
00016 /*
00017  *  Patterns are 16 X 16, ordered left to right, bottom to top.
00018  *  Each byte represents a column in an 8-bit high row.
00019  */
00020 
00021 unsigned char pattern[NPATS+4][PATSIZE/8][PATSIZE] = {
00022     {                                     /* solid */
00023        {
00024            0377,0377,0377,0377,0377,0377,0377,0377,
00025            0377,0377,0377,0377,0377,0377,0377,0377
00026        }, {
00027            0377,0377,0377,0377,0377,0377,0377,0377,
00028            0377,0377,0377,0377,0377,0377,0377,0377
00029        }
00030     }, {                                  /* thick \\\ (dashed) */
00031        {
00032            0377,0177,077,037,017,0207,0303,0341,
00033            0360,0370,0374,0376,0377,0377,0377,0377
00034        }, {
00035            0360,0370,0374,0376,0377,0377,0377,0377,
00036            0377,0177,077,037,017,0207,0303,0341
00037        }
00038     }, {                                  /* thin \\\ (dotted) */
00039        {
00040            0314,0146,063,0231,0314,0146,063,0231,
00041            0314,0146,063,0231,0314,0146,063,0231
00042        }, {
00043            0314,0146,063,0231,0314,0146,063,0231,
00044            0314,0146,063,0231,0314,0146,063,0231
00045        }
00046     }, {                                  /* mix \\\ (dotted-dashed) */
00047        {
00048            0376,0177,077,037,0217,0307,0343,0161,
00049            070,034,0216,0307,0343,0361,0370,0374
00050        }, {
00051            070,034,0216,0307,0343,0361,0370,0374,
00052            0376,0177,077,037,0217,0307,0343,0161
00053        }
00054     }, {                                  /* thick /// (dashed) */
00055        {
00056            0377,0377,0377,0377,0376,0374,0370,0360,
00057            0341,0303,0207,017,037,077,0177,0377
00058        }, {
00059            0341,0303,0207,017,037,077,0177,0377,
00060            0377,0377,0377,0377,0376,0374,0370,0360
00061        }
00062     }, {                                  /* thin /// (dotted) */
00063        {
00064            0231,063,0146,0314,0231,063,0146,0314,
00065            0231,063,0146,0314,0231,063,0146,0314
00066        }, {
00067            0231,063,0146,0314,0231,063,0146,0314,
00068            0231,063,0146,0314,0231,063,0146,0314
00069        }
00070     }, {                                  /* mix /// (dotted-dashed) */
00071        {
00072            0374,0370,0361,0343,0307,0216,034,070,
00073            0161,0343,0307,0217,037,077,0177,0376
00074        }, {
00075            0161,0343,0307,0217,037,077,0177,0376,
00076            0374,0370,0361,0343,0307,0216,034,070
00077        }
00078     }, {                                  /* crisscross */
00079        {
00080            0201,0102,044,030,030,044,0102,0201,
00081            0201,0102,044,030,030,044,0102,0201
00082        }, {
00083            0201,0102,044,030,030,044,0102,0201,
00084            0201,0102,044,030,030,044,0102,0201
00085        }
00086     }, {                                  /* web */
00087        {
00088            0377,0300,0240,0220,0210,0204,0202,0201,
00089            0201,0202,0204,0210,0220,0240,0300,0200
00090        }, {
00091            0377,02,04,010,020,040,0100,0200,
00092            0200,0100,040,020,010,04,02,01
00093        }
00094     }
00095 };
00096 
00097 static int  context = 0;
00098 
00099 struct setting {
00100        int  cnx;            /* setting context */
00101        char  *val;          /* attribute value */
00102        struct setting  *snext;     /* next setting in list */
00103 };
00104 
00105 static struct setting  *sets[0200];
00106 
00107 static void spop(int attrib);
00108 static int spat(int  pat, char  *patval);
00109 
00110 void
00111 set(          /* set attribute to value */
00112 int  attrib,
00113 char  *value
00114 )
00115 {
00116     struct setting  *newset;
00117 
00118     switch (attrib) {
00119        case SALL:
00120            context++;
00121            return;
00122        case SPAT0:
00123        case SPAT1:
00124        case SPAT2:
00125        case SPAT3:
00126            if (!spat(attrib, value)) {
00127               sprintf(errmsg, "Bad pattern set value: %s", value);
00128               error(WARNING, errmsg);
00129               return;
00130            }
00131            break;
00132        default:
00133            sprintf(errmsg, "Can't set attribute: %o", attrib);
00134            error(WARNING, errmsg);
00135            return;
00136     }
00137     newset = (struct setting *)malloc(sizeof(struct setting));
00138     newset->cnx = context;
00139     newset->val = savestr(value);
00140     newset->snext = sets[attrib];
00141     sets[attrib] = newset;
00142 }
00143 
00144 
00145 
00146 void
00147 unset(               /* return attribute to previous setting */
00148 int  attrib
00149 )
00150 {
00151     register int  i;
00152 
00153     if (attrib == SALL) {
00154        if (context == 0)
00155            reset(SALL);
00156        else {
00157            context--;
00158            for (i = 0; i < 0200; i++)
00159               while (sets[i] != NULL && sets[i]->cnx > context)
00160                   spop(i);
00161        }
00162        return;
00163     }
00164     spop(attrib);
00165     if (sets[attrib] == NULL)
00166        reset(attrib);
00167 
00168     switch (attrib) {
00169        case SPAT0:
00170        case SPAT1:
00171        case SPAT2:
00172        case SPAT3:
00173            spat(attrib, sets[attrib]->val);
00174            break;
00175        default:
00176            sprintf(errmsg, "Can't unset attribute: %o", attrib);
00177            error(WARNING, errmsg);
00178            return;
00179     }
00180 }
00181 
00182 
00183 
00184 void
00185 reset(               /* return attribute to default setting */
00186 int  attrib
00187 )
00188 {
00189     switch (attrib) {
00190        case SALL:
00191            reset(SPAT0);
00192            reset(SPAT1);
00193            reset(SPAT2);
00194            reset(SPAT3);
00195            context = 0;
00196            return;
00197        case SPAT0:
00198            spat(SPAT0, "P0");
00199            break;
00200        case SPAT1:
00201            spat(SPAT1, "P1");
00202            break;
00203        case SPAT2:
00204            spat(SPAT2, "P2");
00205            break;
00206        case SPAT3:
00207            spat(SPAT3, "P3");
00208            break;
00209        default:
00210            sprintf(errmsg, "Can't reset attribute: %o", attrib);
00211            error(WARNING, errmsg);
00212            return;
00213     }
00214     while (sets[attrib] != NULL)
00215        spop(attrib);
00216 }
00217 
00218 
00219 
00220 static void
00221 spop(                /* pop top off attrib settings list */
00222 int  attrib
00223 )
00224 {
00225 
00226     if (sets[attrib] != NULL) {
00227        if (sets[attrib]->val != NULL)
00228            freestr(sets[attrib]->val);
00229        free((char *)sets[attrib]);
00230        sets[attrib] = sets[attrib]->snext;
00231     }
00232 
00233 }
00234 
00235 
00236 
00237 static int
00238 spat(                /* set a pattern */
00239 int  pat,
00240 char  *patval
00241 )
00242 {
00243     int  n, i, j, v;
00244     register char  *cp;
00245 
00246     if (patval == NULL) return(FALSE);
00247 
00248     if (patval[0] == 'P' || patval[0] == 'p') {
00249        if (nextscan(patval+1, "%d", (char*)&n) == NULL || n < 0 || n >= NPATS)
00250            return(FALSE);
00251     } else {
00252        n = NPATS + pat - SPAT0;
00253        cp = patval;
00254        for (i = 0; i < PATSIZE>>3; i++)
00255            for (j = 0; j < PATSIZE; j++) {
00256               if ((cp = nextscan(cp, "%o", (char*)&v)) == NULL || v < 0 || v > 0377)
00257                   return(FALSE);
00258               pattern[n][i][j] = v;
00259            }
00260     }
00261     pati[pat-SPAT0] = n;
00262     return(TRUE);
00263 }