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