PLplot 5.9.6
plsdef.c
00001 /* $Id$
00002  *
00003  *      Routines to set various plplot parameters, such as char height,
00004  *      symbol size, tick length, line and fill patterns, etc.
00005  *
00006  * Copyright (C) 2004  Alan W. Irwin
00007  *
00008  * This file is part of PLplot.
00009  *
00010  * PLplot is free software; you can redistribute it and/or modify
00011  * it under the terms of the GNU General Library Public License as published
00012  * by the Free Software Foundation; either version 2 of the License, or
00013  * (at your option) any later version.
00014  *
00015  * PLplot is distributed in the hope that it will be useful,
00016  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  * GNU Library General Public License for more details.
00019  *
00020  * You should have received a copy of the GNU Library General Public License
00021  * along with PLplot; if not, write to the Free Software
00022  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
00023  */
00024 
00025 #include "plplotP.h"
00026 
00027 /* Line pattern defaults */
00028 
00029 static struct line
00030 {
00031     PLINT nels;
00032     PLINT mark[4];
00033     PLINT space[4];
00034 } line[] = {
00035     {
00036         0,                      /* Continuous line */
00037         {
00038             0, 0, 0, 0
00039         },
00040         {
00041             0, 0, 0, 0
00042         }
00043     },
00044     {
00045         1,
00046         {
00047             1000, 0, 0, 0
00048         },
00049         {
00050             1000, 0, 0, 0
00051         }
00052     },
00053     {
00054         1,
00055         {
00056             2000, 0, 0, 0
00057         },
00058         {
00059             2000, 0, 0, 0
00060         }
00061     },
00062     {
00063         1,
00064         {
00065             2000, 0, 0, 0
00066         },
00067         {
00068             1000, 0, 0, 0
00069         }
00070     },
00071     {
00072         2,
00073         {
00074             2500, 1000, 0, 0
00075         },
00076         {
00077             1000, 1000, 0, 0
00078         }
00079     },
00080     {
00081         2,
00082         {
00083             2000, 1000, 0, 0
00084         },
00085         {
00086             2000, 1000, 0, 0
00087         }
00088     },
00089     {
00090         3,
00091         {
00092             1000, 1500, 2000, 0
00093         },
00094         {
00095             1000, 1500, 2000, 0
00096         }
00097     },
00098     {
00099         3,
00100         {
00101             1000, 1500, 2000, 0
00102         },
00103         {
00104             1000, 1000, 1000, 0
00105         }
00106     }
00107 };
00108 
00109 /* Fill pattern defaults */
00110 
00111 static struct pattern
00112 {
00113     PLINT nlines;               /* Number of lines in pattern (1 or 2) */
00114     PLINT inc[2];               /* Inclination 10 ths of degrees */
00115     PLINT del[2];               /* Spacing for each line */
00116 } pattern[] = {
00117     {
00118         1,
00119         {
00120             0, 0
00121         },
00122         {
00123             2000, 0
00124         }
00125     },
00126     {
00127         1,
00128         {
00129             900, 0
00130         },
00131         {
00132             2000, 0
00133         }
00134     },
00135     {
00136         1,
00137         {
00138             450, 0
00139         },
00140         {
00141             2000, 0
00142         }
00143     },
00144     {
00145         1,
00146         {
00147             -450, 0
00148         },
00149         {
00150             2000, 0
00151         }
00152     },
00153     {
00154         1,
00155         {
00156             300, 0
00157         },
00158         {
00159             2000, 0
00160         }
00161     },
00162     {
00163         1,
00164         {
00165             -300, 0
00166         },
00167         {
00168             2000, 0
00169         }
00170     },
00171     {
00172         2,
00173         {
00174             0, 900
00175         },
00176         {
00177             2000, 2000
00178         }
00179     },
00180     {
00181         2,
00182         {
00183             450, -450
00184         },
00185         {
00186             2000, 2000
00187         }
00188     }
00189 };
00190 
00191 /* Set defining parameters for pattern fill */
00192 
00193 static void
00194 spat( PLINT inc[], PLINT del[], PLINT nlin );
00195 
00196 /*----------------------------------------------------------------------*\
00197  * void plschr()
00198  *
00199  * Set character height.
00200  \*----------------------------------------------------------------------*/
00201 
00202 void
00203 c_plschr( PLFLT def, PLFLT scale )
00204 {
00205     if ( def != 0.0 )
00206         plsc->chrdef = def;
00207 
00208     plsc->chrht = scale * plsc->chrdef;
00209 }
00210 
00211 /*----------------------------------------------------------------------*\
00212  * void plsmin()
00213  *
00214  * Set up lengths of minor tick marks.
00215  \*----------------------------------------------------------------------*/
00216 
00217 void
00218 c_plsmin( PLFLT def, PLFLT scale )
00219 {
00220     if ( def != 0.0 )
00221         plsc->mindef = def;
00222 
00223     plsc->minht = scale * plsc->mindef;
00224 }
00225 
00226 /*----------------------------------------------------------------------*\
00227  * void plsmaj()
00228  *
00229  * Set up lengths of major tick marks.
00230  \*----------------------------------------------------------------------*/
00231 
00232 void
00233 c_plsmaj( PLFLT def, PLFLT scale )
00234 {
00235     if ( def != 0.0 )
00236         plsc->majdef = def;
00237 
00238     plsc->majht = scale * plsc->majdef;
00239 }
00240 
00241 /*----------------------------------------------------------------------*\
00242  * void plssym()
00243  *
00244  * Set symbol height.
00245  \*----------------------------------------------------------------------*/
00246 
00247 void
00248 c_plssym( PLFLT def, PLFLT scale )
00249 {
00250     if ( def != 0.0 )
00251         plsc->symdef = def;
00252 
00253     plsc->symht = scale * plsc->symdef;
00254 }
00255 
00256 /*----------------------------------------------------------------------*\
00257  * void pllsty()
00258  *
00259  * Set line style.
00260  \*----------------------------------------------------------------------*/
00261 
00262 void
00263 c_pllsty( PLINT lin )
00264 {
00265     if ( plsc->level < 1 )
00266     {
00267         plabort( "pllsty: Please call plinit first" );
00268         return;
00269     }
00270     if ( lin < 1 || lin > 8 )
00271     {
00272         plabort( "pllsty: Invalid line style" );
00273         return;
00274     }
00275 
00276     plsc->line_style = lin;
00277     plstyl( line[lin - 1].nels,
00278         &line[lin - 1].mark[0], &line[lin - 1].space[0] );
00279 }
00280 
00281 /*----------------------------------------------------------------------*\
00282  * void plpat()
00283  *
00284  * Set fill pattern directly.
00285  \*----------------------------------------------------------------------*/
00286 
00287 void
00288 c_plpat( PLINT nlin, PLINT *inc, PLINT *del )
00289 {
00290     PLINT i;
00291 
00292     if ( plsc->level < 1 )
00293     {
00294         plabort( "plpat: Please call plinit first" );
00295         return;
00296     }
00297     if ( nlin < 1 || nlin > 2 )
00298     {
00299         plabort( "plpat: Only 1 or 2 line styles allowed" );
00300         return;
00301     }
00302     for ( i = 0; i < nlin; i++ )
00303     {
00304         if ( del[i] < 0 )
00305         {
00306             plabort( "plpat: Line spacing must be greater than 0" );
00307             return;
00308         }
00309     }
00310     spat( inc, del, nlin );
00311 }
00312 
00313 /*----------------------------------------------------------------------*\
00314  * void plpsty()
00315  *
00316  * Set fill pattern, using one of the predefined patterns.
00317  * A fill pattern <= 0 indicates hardware fill.
00318  \*----------------------------------------------------------------------*/
00319 
00320 void
00321 c_plpsty( PLINT patt )
00322 {
00323     if ( plsc->level < 1 )
00324     {
00325         plabort( "plpsty: Please call plinit first" );
00326         return;
00327     }
00328     if ( patt > 8 )
00329     {
00330         plabort( "plpsty: Invalid pattern" );
00331         return;
00332     }
00333     if ( patt != plsc->patt )
00334     {
00335         plsc->patt = patt;
00336 
00337         if ( plsc->level > 0 )
00338         {
00339             plP_state( PLSTATE_FILL );
00340         }
00341     }
00342     if ( patt > 0 )
00343     {
00344         spat( &pattern[patt - 1].inc[0], &pattern[patt - 1].del[0],
00345             pattern[patt - 1].nlines );
00346     }
00347 }
00348 
00349 /*----------------------------------------------------------------------*\
00350  * void spat()
00351  *
00352  * Set defining parameters for pattern fill
00353  \*----------------------------------------------------------------------*/
00354 
00355 static void
00356 spat( PLINT inc[], PLINT del[], PLINT nlin )
00357 {
00358     PLINT i;
00359 
00360     plsc->nps = nlin;
00361     for ( i = 0; i < nlin; i++ )
00362     {
00363         plsc->inclin[i] = inc[i];
00364         plsc->delta[i]  = del[i];
00365     }
00366 }
 All Data Structures Files Functions