Back to index

plt-scheme  4.2.1
plpage.c
Go to the documentation of this file.
00001 /* $Id: plpage.c,v 1.1 2004/03/01 20:54:52 cozmic Exp $
00002 
00003        Page/subpage handling routines
00004 */
00005 
00006 #include "plplotP.h"
00007 
00008 /*--------------------------------------------------------------------------*\
00009  * void pladv()
00010  *
00011  * Advance to subpage "page", or to the next one if "page" = 0.
00012 \*--------------------------------------------------------------------------*/
00013 
00014 void
00015 c_pladv(PLINT page)
00016 {
00017     if (plsc->level < 1) {
00018        plabort("pladv: Please call plinit first");
00019        return;
00020     }
00021 
00022     if (page > 0 && page <= plsc->nsubx * plsc->nsuby)
00023        plsc->cursub = page;
00024 
00025     else if (page == 0) {
00026        if (plsc->cursub >= plsc->nsubx * plsc->nsuby) {
00027            plP_eop();
00028            plP_bop();
00029            plsc->cursub = 1;
00030        }
00031        else
00032            plsc->cursub++;
00033     }
00034     else {
00035        plabort("pladv: Invalid subpage number");
00036        return;
00037     }
00038 
00039     plP_setsub();
00040 }
00041 
00042 /*--------------------------------------------------------------------------*\
00043  * void plclear()
00044  *
00045  * Clear current subpage.  Subpages can be set with pladv before 
00046  * calling plclear. Not all drivers support this.
00047 \*--------------------------------------------------------------------------*/
00048 
00049 void
00050 c_plclear(void)
00051 {
00052     if (plsc->level < 1) {
00053        plabort("plclear: Please call plinit first");
00054        return;
00055     }
00056 
00057     if (plsc->dev_clear)
00058       plP_esc(PLESC_CLEAR, NULL);
00059     else { /* driver does not support clear, fill using background color */
00060 
00061          short x[5], y[5];
00062          int ocolor = plsc->icol0;
00063 
00064          x[0] = x[3] = x[4] = plsc->sppxmi;
00065          x[1] = x[2] = plsc->sppxma;
00066          y[0] = y[1] = y[4] = plsc->sppymi;
00067          y[2] = y[3] = plsc->sppyma;
00068          plcol0(0);
00069          plP_fill(x, y, 5);
00070          plcol0(ocolor);
00071     }
00072 }
00073 
00074 /*--------------------------------------------------------------------------*\
00075  * void pleop()
00076  *
00077  * End current page.
00078 \*--------------------------------------------------------------------------*/
00079 
00080 void
00081 c_pleop(void)
00082 {
00083     if (plsc->level < 1) {
00084        plabort("pleop: Please call plinit first");
00085        return;
00086     }
00087 
00088     plsc->cursub = plsc->nsubx * plsc->nsuby;
00089     plP_eop();
00090 }
00091 
00092 /*--------------------------------------------------------------------------*\
00093  * void plbop()
00094  *
00095  * Start new page.  Should only be used with pleop().
00096 \*--------------------------------------------------------------------------*/
00097 
00098 void
00099 c_plbop(void)
00100 {
00101     if (plsc->level < 1) {
00102        plabort("pladv: Please call plinit first");
00103        return;
00104     }
00105     plP_bop();
00106     plsc->cursub = 1;
00107     plP_setsub();
00108 }
00109 
00110 /*--------------------------------------------------------------------------*\
00111  * void plP_subpInit()
00112  *
00113  * Set up plot parameters according to the number of subpages.
00114 \*--------------------------------------------------------------------------*/
00115 
00116 void
00117 plP_subpInit(void)
00118 {
00119     PLFLT scale, size_chr, size_sym, size_maj, size_min;
00120 
00121 /* Subpage checks */
00122 
00123     if (plsc->nsubx <= 0)
00124        plsc->nsubx = 1;
00125     if (plsc->nsuby <= 0)
00126        plsc->nsuby = 1;
00127 
00128     plsc->cursub = 0;
00129 
00130 /*
00131  * Set default sizes
00132  * Global scaling:
00133  *     Normalize to the page length for more uniform results.
00134  *     A virtual page length of 200 mm is assumed.
00135  * Subpage scaling:
00136  *     Reduce sizes with plot area (non-proportional, so that character
00137  *     size doesn't get too small).
00138  */
00139     scale = 0.5 *
00140        ((plsc->phyxma - plsc->phyxmi) / plsc->xpmm +
00141         (plsc->phyyma - plsc->phyymi) / plsc->ypmm) / 200.0;
00142 
00143     if (plsc->nsuby > 1)
00144        scale /= sqrt((double) plsc->nsuby);
00145 
00146     size_chr = 4.0;
00147     size_sym = 4.0;         /* All these in virtual plot units */
00148     size_maj = 3.0;
00149     size_min = 1.5;
00150 
00151     plsc->chrdef = plsc->chrht = size_chr * scale;
00152     plsc->symdef = plsc->symht = size_sym * scale;
00153     plsc->majdef = plsc->majht = size_maj * scale;
00154     plsc->mindef = plsc->minht = size_min * scale;
00155 }
00156 
00157 /*--------------------------------------------------------------------------*\
00158  * void plP_setsub()
00159  *
00160  * Set up the subpage boundaries according to the current subpage selected.
00161 \*--------------------------------------------------------------------------*/
00162 
00163 void
00164 plP_setsub(void)
00165 {
00166     PLINT ix, iy;
00167 
00168     ix = (plsc->cursub - 1) % plsc->nsubx;
00169     iy = plsc->nsuby - (plsc->cursub - 1) / plsc->nsubx;
00170 
00171     plsc->spdxmi = (PLFLT) (ix)     / (PLFLT) (plsc->nsubx);
00172     plsc->spdxma = (PLFLT) (ix + 1) / (PLFLT) (plsc->nsubx);
00173     plsc->spdymi = (PLFLT) (iy - 1) / (PLFLT) (plsc->nsuby);
00174     plsc->spdyma = (PLFLT) (iy)     / (PLFLT) (plsc->nsuby);
00175 
00176     plsc->sppxmi = plP_dcpcx(plsc->spdxmi);
00177     plsc->sppxma = plP_dcpcx(plsc->spdxma);
00178     plsc->sppymi = plP_dcpcy(plsc->spdymi);
00179     plsc->sppyma = plP_dcpcy(plsc->spdyma);
00180 
00181     plP_sclp(plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma);
00182 }
00183 
00184 /*--------------------------------------------------------------------------*\
00185  * void plgspa()
00186  *
00187  * Get subpage boundaries in absolute coordinates (mm from bottom
00188  * left-hand corner of page.
00189 \*--------------------------------------------------------------------------*/
00190 
00191 void
00192 c_plgspa(PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax)
00193 {
00194     if (plsc->level < 1) {
00195        plabort("plgspa: Please call plinit first");
00196        return;
00197     }
00198     *xmin = plP_dcmmx(plsc->spdxmi);
00199     *xmax = plP_dcmmx(plsc->spdxma);
00200     *ymin = plP_dcmmy(plsc->spdymi);
00201     *ymax = plP_dcmmy(plsc->spdyma);
00202 }
00203 
00204 /*--------------------------------------------------------------------------*\
00205  * int plGetCursor()
00206  *
00207  * Wait for graphics input event and translate to world coordinates.
00208  * Returns 0 if no translation to world coordinates is possible.  
00209  * Written by Paul Casteels.
00210 \*--------------------------------------------------------------------------*/
00211 
00212 int
00213 plGetCursor(PLGraphicsIn *plg)
00214 {
00215     plP_esc(PLESC_GETC, plg);
00216     return plTranslateCursor(plg);
00217 }
00218 
00219 /*--------------------------------------------------------------------------*\
00220  * int plTranslateCursor()
00221  *
00222  * Translates cursor position from relative device coordinates to world
00223  * coordinates.  Returns 0 if no translation to world coordinates is
00224  * possible.  Written by Paul Casteels and modified by Alan W. Irwin.
00225 \*--------------------------------------------------------------------------*/
00226 
00227 int
00228 plTranslateCursor(PLGraphicsIn *plg)
00229 {
00230     int window;
00231     c_plcalc_world(plg->dX, plg->dY, &plg->wX, &plg->wY, 
00232                  (PLINT *) &window);
00233     if ( window >= 0 ) { 
00234        plg->subwindow = window;
00235        return 1;
00236     }
00237     else
00238        return 0;
00239 }
00240 
00241 /*--------------------------------------------------------------------------*\
00242  * void c_plcalc_world
00243  *
00244  * Calculate world coordinates wx, and wy from relative device coordinates, rx
00245  * and ry.  Also, return the window index for which the world coordinates 
00246  * are valid. window is set to -1 and wx and wy to 0. if rx and ry do not 
00247  * correspond to valid world coordinates for any currently existing window.
00248  * Originally written by Paul Casteels and modified by Alan W. Irwin.
00249 \*--------------------------------------------------------------------------*/
00250 
00251 void
00252 c_plcalc_world(PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window)
00253 {
00254     int i;
00255     int lastwin = plsc->nplwin - 1;
00256     int firstwin = MAX(plsc->nplwin - PL_MAXWINDOWS, 0);
00257     PLWindow *w;
00258 
00259     for (i = lastwin; i >= firstwin; i--) {
00260        w = &plsc->plwin[i % PL_MAXWINDOWS];
00261        if ((rx >= w->dxmi) &&
00262            (rx <= w->dxma) &&
00263            (ry >= w->dymi) &&
00264            (ry <= w->dyma) ) {
00265 
00266            *wx = w->wxmi + (rx - w->dxmi) * 
00267               (w->wxma - w->wxmi) / (w->dxma - w->dxmi);
00268 
00269            *wy = w->wymi + (ry - w->dymi) * 
00270               (w->wyma - w->wymi) / (w->dyma - w->dymi);
00271           
00272            *window = i;
00273 
00274            return;
00275        }
00276     }
00277     /* No valid window found with these relative coordinates. */
00278     *wx = 0.;
00279     *wy = 0.;
00280     *window = -1;
00281     return;
00282 }