PLplot 5.9.6
|
00001 /* $Id$ 00002 * 00003 * Copyright (C) 2004 Alan W. Irwin 00004 * 00005 * This file is part of PLplot. 00006 * 00007 * PLplot is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Library Public License as published 00009 * by the Free Software Foundation; either version 2 of the License, or 00010 * (at your option) any later version. 00011 * 00012 * PLplot is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU Library General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU Library General Public License 00018 * along with PLplot; if not, write to the Free Software 00019 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 */ 00021 00028 #include "plplotP.h" 00029 00030 00031 /*--------------------------------------------------------------------------*/ 00036 void 00037 c_pladv( PLINT page ) 00038 { 00039 if ( plsc->level < 1 ) 00040 { 00041 plabort( "pladv: Please call plinit first" ); 00042 return; 00043 } 00044 00045 if ( page > 0 && page <= plsc->nsubx * plsc->nsuby ) 00046 plsc->cursub = page; 00047 00048 else if ( page == 0 ) 00049 { 00050 if ( plsc->cursub >= plsc->nsubx * plsc->nsuby ) 00051 { 00052 plP_eop(); 00053 plP_bop(); 00054 plsc->cursub = 1; 00055 } 00056 else 00057 plsc->cursub++; 00058 } 00059 else 00060 { 00061 plabort( "pladv: Invalid subpage number" ); 00062 return; 00063 } 00064 00065 plP_setsub(); 00066 } 00067 00068 00069 /*--------------------------------------------------------------------------*/ 00073 void 00074 c_plclear( void ) 00075 { 00076 if ( plsc->level < 1 ) 00077 { 00078 plabort( "plclear: Please call plinit first" ); 00079 return; 00080 } 00081 00082 if ( plsc->dev_clear ) 00083 plP_esc( PLESC_CLEAR, NULL ); 00084 else /* driver does not support clear, fill using background color */ 00085 00086 { 00087 short x[5], y[5]; 00088 int ocolor = plsc->icol0; 00089 00090 x[0] = x[3] = x[4] = plsc->sppxmi; 00091 x[1] = x[2] = plsc->sppxma; 00092 y[0] = y[1] = y[4] = plsc->sppymi; 00093 y[2] = y[3] = plsc->sppyma; 00094 plcol0( 0 ); 00095 plP_fill( x, y, 5 ); 00096 plcol0( ocolor ); 00097 } 00098 } 00099 00100 00101 /*--------------------------------------------------------------------------*/ 00104 void 00105 c_pleop( void ) 00106 { 00107 if ( plsc->level < 1 ) 00108 { 00109 plabort( "pleop: Please call plinit first" ); 00110 return; 00111 } 00112 00113 plsc->cursub = plsc->nsubx * plsc->nsuby; 00114 plP_eop(); 00115 } 00116 00117 00118 /*--------------------------------------------------------------------------*/ 00121 void 00122 c_plbop( void ) 00123 { 00124 if ( plsc->level < 1 ) 00125 { 00126 plabort( "plbop: Please call plinit first" ); 00127 return; 00128 } 00129 plP_bop(); 00130 plsc->cursub = 1; 00131 plP_setsub(); 00132 } 00133 00134 00135 /*--------------------------------------------------------------------------*/ 00138 void 00139 plP_subpInit( void ) 00140 { 00141 PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat; 00142 00143 /* Subpage checks */ 00144 00145 if ( plsc->nsubx <= 0 ) 00146 plsc->nsubx = 1; 00147 if ( plsc->nsuby <= 0 ) 00148 plsc->nsuby = 1; 00149 00150 plsc->cursub = 0; 00151 00152 /* 00153 * Set default sizes 00154 * Global scaling: 00155 * Normalize to the page length for more uniform results. 00156 * A virtual page length of 200 mm is assumed. 00157 * Subpage scaling: 00158 * Reduce sizes with plot area (non-proportional, so that character 00159 * size doesn't get too small). 00160 */ 00161 scale = 0.5 * 00162 ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm + 00163 ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0; 00164 00165 /* Take account of scaling caused by change of orientation */ 00166 if ( plsc->difilt && PLDI_ORI ) 00167 { 00168 theta = 0.5 * M_PI * plsc->diorot; 00169 rat = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) / 00170 ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ); 00171 rat = MAX( rat, 1.0 / rat ); 00172 rat = fabs( cos( theta ) ) + rat*fabs( sin( theta ) ); 00173 scale /= rat; 00174 } 00175 00176 if ( plsc->nsuby > 1 ) 00177 scale /= sqrt( (double) plsc->nsuby ); 00178 00179 size_chr = 4.0; 00180 size_sym = 4.0; /* All these in virtual plot units */ 00181 size_maj = 3.0; 00182 size_min = 1.5; 00183 00184 plsc->chrdef = plsc->chrht = size_chr * scale; 00185 plsc->symdef = plsc->symht = size_sym * scale; 00186 plsc->majdef = plsc->majht = size_maj * scale; 00187 plsc->mindef = plsc->minht = size_min * scale; 00188 } 00189 00190 00191 /*--------------------------------------------------------------------------*/ 00194 void 00195 plP_setsub( void ) 00196 { 00197 PLINT ix, iy; 00198 00199 ix = ( plsc->cursub - 1 ) % plsc->nsubx; 00200 iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx; 00201 00202 plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx ); 00203 plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx ); 00204 plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby ); 00205 plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby ); 00206 00207 plsc->sppxmi = plP_dcpcx( plsc->spdxmi ); 00208 plsc->sppxma = plP_dcpcx( plsc->spdxma ); 00209 plsc->sppymi = plP_dcpcy( plsc->spdymi ); 00210 plsc->sppyma = plP_dcpcy( plsc->spdyma ); 00211 00212 plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma ); 00213 } 00214 00215 00216 /*--------------------------------------------------------------------------*/ 00225 void 00226 c_plgspa( PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax ) 00227 { 00228 if ( plsc->level < 1 ) 00229 { 00230 plabort( "plgspa: Please call plinit first" ); 00231 return; 00232 } 00233 *xmin = plP_dcmmx( plsc->spdxmi ); 00234 *xmax = plP_dcmmx( plsc->spdxma ); 00235 *ymin = plP_dcmmy( plsc->spdymi ); 00236 *ymax = plP_dcmmy( plsc->spdyma ); 00237 } 00238 00239 00240 /*--------------------------------------------------------------------------*/ 00248 int 00249 plGetCursor( PLGraphicsIn *plg ) 00250 { 00251 plP_esc( PLESC_GETC, plg ); 00252 return plTranslateCursor( plg ); 00253 } 00254 00255 00256 /*--------------------------------------------------------------------------*/ 00264 int 00265 plTranslateCursor( PLGraphicsIn *plg ) 00266 { 00267 int window; 00268 c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY, 00269 (PLINT *) &window ); 00270 if ( window >= 0 ) 00271 { 00272 plg->subwindow = window; 00273 return 1; 00274 } 00275 else 00276 return 0; 00277 } 00278 00279 00280 /*--------------------------------------------------------------------------*/ 00294 void 00295 c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window ) 00296 { 00297 int i; 00298 int lastwin = plsc->nplwin - 1; 00299 int firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 ); 00300 PLWindow *w; 00301 00302 for ( i = lastwin; i >= firstwin; i-- ) 00303 { 00304 w = &plsc->plwin[i % PL_MAXWINDOWS]; 00305 if ( ( rx >= w->dxmi ) && 00306 ( rx <= w->dxma ) && 00307 ( ry >= w->dymi ) && 00308 ( ry <= w->dyma ) ) 00309 { 00310 *wx = w->wxmi + ( rx - w->dxmi ) * 00311 ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi ); 00312 00313 *wy = w->wymi + ( ry - w->dymi ) * 00314 ( w->wyma - w->wymi ) / ( w->dyma - w->dymi ); 00315 00316 *window = i; 00317 00318 return; 00319 } 00320 } 00321 /* No valid window found with these relative coordinates. */ 00322 *wx = 0.; 00323 *wy = 0.; 00324 *window = -1; 00325 return; 00326 }