PLplot 5.9.6
|
00001 /* plget/plset() 00002 * 00003 * Copyright (C) 2009 Hazen Babcock 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 00022 #include "plplotP.h" 00023 #include "plstrm.h" 00024 00025 /*------------------------------------------------------------------------- 00026 * plget : Get the value of the specified variable in the current plot stream 00027 *-------------------------------------------------------------------------*/ 00028 void 00029 c_plget( enum PLAttributeName attrName, PLAttribute *attrValue ) 00030 { 00031 PLINT i; 00032 00033 attrValue->attributeType = -1; 00034 switch ( attrName ) 00035 { 00036 /* get the entire color map 0 */ 00037 case PL_CMAP0: 00038 attrValue->attributeType = PL_COLORPTR; 00039 attrValue->colorValues = (PLColor *) malloc( sizeof ( PLColor ) * plsc->ncol0 ); 00040 for ( i = 0; i < plsc->ncol0; i++ ) 00041 { 00042 attrValue->colorValues[i].r = plsc->cmap0[i].r; 00043 attrValue->colorValues[i].g = plsc->cmap0[i].g; 00044 attrValue->colorValues[i].b = plsc->cmap0[i].b; 00045 attrValue->colorValues[i].a = plsc->cmap0[i].a; 00046 } 00047 attrValue->nValues = plsc->ncol0; 00048 break; 00049 /* get the entire color map 1 */ 00050 case PL_CMAP1: 00051 attrValue->attributeType = PL_COLORPTR; 00052 attrValue->colorValues = (PLColor *) malloc( sizeof ( PLColor ) * plsc->ncol1 ); 00053 for ( i = 0; i < plsc->ncol1; i++ ) 00054 { 00055 attrValue->colorValues[i].r = plsc->cmap1[i].r; 00056 attrValue->colorValues[i].g = plsc->cmap1[i].g; 00057 attrValue->colorValues[i].b = plsc->cmap1[i].b; 00058 attrValue->colorValues[i].a = plsc->cmap1[i].a; 00059 } 00060 attrValue->nValues = plsc->ncol1; 00061 break; 00062 /* get the current (scaled) character height */ 00063 case PL_CURCHARSIZE: 00064 attrValue->attributeType = PL_FLT; 00065 attrValue->fltValue = plsc->chrht; 00066 break; 00067 /* get the current color map 0 color */ 00068 case PL_CURCOLOR0: 00069 attrValue->attributeType = PL_COLOR; 00070 attrValue->colorValue.r = plsc->curcolor.r; 00071 attrValue->colorValue.g = plsc->curcolor.g; 00072 attrValue->colorValue.b = plsc->curcolor.b; 00073 attrValue->colorValue.a = plsc->curcolor.a; 00074 break; 00075 /* get the current (scaled) major tick size */ 00076 case PL_CURMAJORTICK: 00077 attrValue->attributeType = PL_FLT; 00078 attrValue->fltValue = plsc->majht; 00079 break; 00080 /* get the current (scaled) minor tick size */ 00081 case PL_CURMINORTICK: 00082 attrValue->attributeType = PL_FLT; 00083 attrValue->fltValue = plsc->minht; 00084 break; 00085 /* get the default character height (in mm) */ 00086 case PL_DEFCHARSIZE: 00087 attrValue->attributeType = PL_FLT; 00088 attrValue->fltValue = plsc->chrdef; 00089 break; 00090 /* get the default major tick size (in mm) */ 00091 case PL_DEFMAJORTICK: 00092 attrValue->attributeType = PL_FLT; 00093 attrValue->fltValue = plsc->majdef; 00094 break; 00095 /* get the default minor tick size (in mm) */ 00096 case PL_DEFMINORTICK: 00097 attrValue->attributeType = PL_FLT; 00098 attrValue->fltValue = plsc->mindef; 00099 break; 00100 /* get the index of the current color map 0 color */ 00101 case PL_ICOL0: 00102 attrValue->attributeType = PL_INT; 00103 attrValue->intValue = plsc->icol0; 00104 break; 00105 /* get the index of the current color map 1 color */ 00106 case PL_ICOL1: 00107 attrValue->attributeType = PL_FLT; 00108 attrValue->intValue = ( (PLFLT) plsc->icol1 ) / ( (PLFLT) plsc->ncol1 ); 00109 break; 00110 /* get the number of colors in color map 0 */ 00111 case PL_NCOL0: 00112 attrValue->attributeType = PL_INT; 00113 attrValue->intValue = plsc->ncol0; 00114 break; 00115 /* get the number of colors in color map 1 */ 00116 case PL_NCOL1: 00117 attrValue->attributeType = PL_INT; 00118 attrValue->intValue = plsc->ncol1; 00119 break; 00120 /* get the current pen width */ 00121 case PL_PENWIDTH: 00122 attrValue->attributeType = PL_INT; 00123 attrValue->intValue = plsc->width; 00124 break; 00125 /* get the current number of digits of precision */ 00126 case PL_PRECISION: 00127 attrValue->attributeType = PL_INT; 00128 attrValue->intValue = plsc->precis; 00129 break; 00130 /* get whether or not to use user specified number of digits of precision */ 00131 case PL_SETPRECISION: 00132 attrValue->attributeType = PL_INT; 00133 attrValue->intValue = plsc->setpre; 00134 break; 00135 /* get x fields digit value (?) */ 00136 case PL_XDIGITS: 00137 attrValue->attributeType = PL_INT; 00138 attrValue->intValue = plsc->xdigits; 00139 break; 00140 /* get x maximum digits (0 = no maximum) */ 00141 case PL_XDIGMAX: 00142 attrValue->attributeType = PL_INT; 00143 attrValue->intValue = plsc->xdigmax; 00144 break; 00145 /* get y fields digit value (?) */ 00146 case PL_YDIGITS: 00147 attrValue->attributeType = PL_INT; 00148 attrValue->intValue = plsc->ydigits; 00149 break; 00150 /* get y maximum digits (0 = no maximum) */ 00151 case PL_YDIGMAX: 00152 attrValue->attributeType = PL_INT; 00153 attrValue->intValue = plsc->ydigmax; 00154 break; 00155 /* get z fields digit value (?) */ 00156 case PL_ZDIGITS: 00157 attrValue->attributeType = PL_INT; 00158 attrValue->intValue = plsc->zdigits; 00159 break; 00160 /* get z maximum digits (0 = no maximum) */ 00161 case PL_ZDIGMAX: 00162 attrValue->attributeType = PL_INT; 00163 attrValue->intValue = plsc->zdigmax; 00164 break; 00165 default: 00166 break; 00167 } 00168 } 00169 00170 /*------------------------------------------------------------------------- 00171 * plset : Set the value of the specified variable in the current plot stream 00172 * 00173 * Note: This is a little tricker since we can't just set the value & expect 00174 * the driver to respond, instead we have to call the appropriate function 00175 * in PLplot core. 00176 * 00177 *-------------------------------------------------------------------------*/ 00178 void 00179 c_plset( enum PLAttributeName attrName, PLAttribute attrValue ) 00180 { 00181 PLINT i; 00182 PLINT *r, *g, *b; 00183 PLFLT *a; 00184 00185 switch ( attrName ) 00186 { 00187 /* set color map 0 from an array of PL_COLOR values */ 00188 case PL_CMAP0: 00189 if ( attrValue.attributeType == PL_COLORPTR ) 00190 { 00191 r = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00192 g = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00193 b = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00194 a = (PLFLT *) malloc( sizeof ( PLFLT ) * attrValue.nValues ); 00195 for ( i = 0; i < attrValue.nValues; i++ ) 00196 { 00197 r[i] = attrValue.colorValues[i].r; 00198 g[i] = attrValue.colorValues[i].g; 00199 b[i] = attrValue.colorValues[i].b; 00200 a[i] = attrValue.colorValues[i].a; 00201 } 00202 plscmap0a( r, g, b, a, attrValue.nValues ); 00203 free( r ); 00204 free( g ); 00205 free( b ); 00206 free( a ); 00207 } 00208 break; 00209 /* set color map 1 from an array of PL_COLOR values */ 00210 case PL_CMAP1: 00211 if ( attrValue.attributeType == PL_COLORPTR ) 00212 { 00213 r = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00214 g = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00215 b = (PLINT *) malloc( sizeof ( PLINT ) * attrValue.nValues ); 00216 a = (PLFLT *) malloc( sizeof ( PLFLT ) * attrValue.nValues ); 00217 for ( i = 0; i < attrValue.nValues; i++ ) 00218 { 00219 r[i] = attrValue.colorValues[i].r; 00220 g[i] = attrValue.colorValues[i].g; 00221 b[i] = attrValue.colorValues[i].b; 00222 a[i] = attrValue.colorValues[i].a; 00223 } 00224 plscmap1a( r, g, b, a, attrValue.nValues ); 00225 free( r ); 00226 free( g ); 00227 free( b ); 00228 free( a ); 00229 } 00230 break; 00231 /* set the (scaled) character height */ 00232 case PL_CURCHARSIZE: 00233 if ( attrValue.attributeType == PL_FLT ) 00234 { 00235 plschr( 0.0, attrValue.fltValue ); 00236 } 00237 break; 00238 /* set the current color map 0 color */ 00239 case PL_CURCOLOR0: 00240 if ( attrValue.attributeType == PL_COLOR ) 00241 { 00242 plscol0( plsc->icol0, 00243 attrValue.colorValue.r, 00244 attrValue.colorValue.g, 00245 attrValue.colorValue.b ); 00246 plcol0( plsc->icol0 ); 00247 } 00248 break; 00249 /* set the (scaled) major tick length */ 00250 case PL_CURMAJORTICK: 00251 if ( attrValue.attributeType == PL_FLT ) 00252 { 00253 plsmaj( 0.0, attrValue.fltValue ); 00254 } 00255 break; 00256 /* set the (scaled) minor tick length */ 00257 case PL_CURMINORTICK: 00258 if ( attrValue.attributeType == PL_FLT ) 00259 { 00260 plsmin( 0.0, attrValue.fltValue ); 00261 } 00262 break; 00263 /* set the default character height (mm) */ 00264 case PL_DEFCHARSIZE: 00265 if ( attrValue.attributeType == PL_FLT ) 00266 { 00267 plschr( attrValue.fltValue, plsc->chrht ); 00268 } 00269 break; 00270 /* set the default major tick size (mm) */ 00271 case PL_DEFMAJORTICK: 00272 if ( attrValue.attributeType == PL_FLT ) 00273 { 00274 plsmaj( attrValue.fltValue, plsc->majht ); 00275 } 00276 break; 00277 /* set the default minor tick size (mm) */ 00278 case PL_DEFMINORTICK: 00279 if ( attrValue.attributeType == PL_FLT ) 00280 { 00281 plsmin( attrValue.fltValue, plsc->minht ); 00282 } 00283 break; 00284 /* set the index of the current color map 0 color */ 00285 case PL_ICOL0: 00286 if ( attrValue.attributeType == PL_INT ) 00287 { 00288 plcol0( attrValue.intValue ); 00289 } 00290 break; 00291 /* set the index of the current color map 1 color */ 00292 case PL_ICOL1: 00293 if ( attrValue.attributeType == PL_FLT ) 00294 { 00295 plcol1( attrValue.fltValue ); 00296 } 00297 break; 00298 /* set the number of colors in color map 0 */ 00299 case PL_NCOL0: 00300 if ( attrValue.attributeType == PL_INT ) 00301 { 00302 plscmap0n( attrValue.intValue ); 00303 } 00304 break; 00305 /* set the number of colors in color map 1 */ 00306 case PL_NCOL1: 00307 if ( attrValue.attributeType == PL_INT ) 00308 { 00309 plscmap1n( attrValue.intValue ); 00310 } 00311 break; 00312 /* set the current pen width */ 00313 case PL_PENWIDTH: 00314 if ( attrValue.attributeType == PL_INT ) 00315 { 00316 plwid( attrValue.intValue ); 00317 } 00318 break; 00319 /* set the current number of digits of precision */ 00320 case PL_PRECISION: 00321 if ( attrValue.attributeType == PL_INT ) 00322 { 00323 plprec( plsc->setpre, attrValue.intValue ); 00324 } 00325 break; 00326 /* set whether or not to use user specified number of digits of precision */ 00327 case PL_SETPRECISION: 00328 if ( attrValue.attributeType == PL_INT ) 00329 { 00330 plprec( attrValue.intValue, plsc->precis ); 00331 } 00332 break; 00333 /* set x fields digit value (?) */ 00334 case PL_XDIGITS: 00335 if ( attrValue.attributeType == PL_INT ) 00336 { 00337 plsxax( plsc->xdigmax, attrValue.intValue ); 00338 } 00339 break; 00340 /* get x maximum digits (0 = no maximum) */ 00341 case PL_XDIGMAX: 00342 if ( attrValue.attributeType == PL_INT ) 00343 { 00344 plsxax( attrValue.intValue, plsc->xdigits ); 00345 } 00346 break; 00347 /* set y fields digit value (?) */ 00348 case PL_YDIGITS: 00349 if ( attrValue.attributeType == PL_INT ) 00350 { 00351 plsyax( plsc->ydigmax, attrValue.intValue ); 00352 } 00353 break; 00354 /* set y maximum digits (0 = no maximum) */ 00355 case PL_YDIGMAX: 00356 if ( attrValue.attributeType == PL_INT ) 00357 { 00358 plsyax( attrValue.intValue, plsc->ydigits ); 00359 } 00360 break; 00361 /* set z fields digit value (?) */ 00362 case PL_ZDIGITS: 00363 if ( attrValue.attributeType == PL_INT ) 00364 { 00365 plszax( plsc->zdigmax, attrValue.intValue ); 00366 } 00367 break; 00368 /* set z maximum digits (0 = no maximum) */ 00369 case PL_ZDIGMAX: 00370 if ( attrValue.attributeType == PL_INT ) 00371 { 00372 plszax( attrValue.intValue, plsc->zdigits ); 00373 } 00374 break; 00375 default: 00376 break; 00377 } 00378 } 00379