• Main Page
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

plpage.c

Go to the documentation of this file.
00001 // $Id: plpage.c 11680 2011-03-27 17:57:51Z airwin $
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 Library General 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 
00026 
00027 #include "plplotP.h"
00028 
00029 //--------------------------------------------------------------------------
00034 void
00035 c_pladv( PLINT page )
00036 {
00037     if ( plsc->level < 1 )
00038     {
00039         plabort( "pladv: Please call plinit first" );
00040         return;
00041     }
00042 
00043     if ( page > 0 && page <= plsc->nsubx * plsc->nsuby )
00044         plsc->cursub = page;
00045 
00046     else if ( page == 0 )
00047     {
00048         if ( plsc->cursub >= plsc->nsubx * plsc->nsuby )
00049         {
00050             plP_eop();
00051             plP_bop();
00052             plsc->cursub = 1;
00053         }
00054         else
00055             plsc->cursub++;
00056     }
00057     else
00058     {
00059         plabort( "pladv: Invalid subpage number" );
00060         return;
00061     }
00062 
00063     plP_setsub();
00064 }
00065 
00066 //--------------------------------------------------------------------------
00069 //
00070 void
00071 c_plclear( void )
00072 {
00073     if ( plsc->level < 1 )
00074     {
00075         plabort( "plclear: Please call plinit first" );
00076         return;
00077     }
00078 
00079     if ( plsc->dev_clear )
00080         plP_esc( PLESC_CLEAR, NULL );
00081     else   // driver does not support clear, fill using background color
00082 
00083     {
00084         short x[5], y[5];
00085         int   ocolor = plsc->icol0;
00086 
00087         x[0] = x[3] = x[4] = plsc->sppxmi;
00088         x[1] = x[2] = plsc->sppxma;
00089         y[0] = y[1] = y[4] = plsc->sppymi;
00090         y[2] = y[3] = plsc->sppyma;
00091         plcol0( 0 );
00092         plP_fill( x, y, 5 );
00093         plcol0( ocolor );
00094     }
00095 }
00096 
00097 //--------------------------------------------------------------------------
00100 void
00101 c_pleop( void )
00102 {
00103     if ( plsc->level < 1 )
00104     {
00105         plabort( "pleop: Please call plinit first" );
00106         return;
00107     }
00108 
00109     plsc->cursub = plsc->nsubx * plsc->nsuby;
00110     plP_eop();
00111 }
00112 
00113 //--------------------------------------------------------------------------
00116 void
00117 c_plbop( void )
00118 {
00119     if ( plsc->level < 1 )
00120     {
00121         plabort( "plbop: Please call plinit first" );
00122         return;
00123     }
00124     plP_bop();
00125     plsc->cursub = 1;
00126     plP_setsub();
00127 }
00128 
00129 //--------------------------------------------------------------------------
00132 void
00133 plP_subpInit( void )
00134 {
00135     PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat;
00136 
00137 // Subpage checks
00138 
00139     if ( plsc->nsubx <= 0 )
00140         plsc->nsubx = 1;
00141     if ( plsc->nsuby <= 0 )
00142         plsc->nsuby = 1;
00143 
00144     plsc->cursub = 0;
00145 
00146 //
00147 // Set default sizes
00148 // Global scaling:
00149 //      Normalize to the page length for more uniform results.
00150 //      A virtual page length of 200 mm is assumed.
00151 // Subpage scaling:
00152 //      Reduce sizes with plot area (non-proportional, so that character
00153 //      size doesn't get too small).
00154 //
00155     scale = 0.5 *
00156             ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm +
00157               ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0;
00158 
00159     // Take account of scaling caused by change of orientation
00160     if ( plsc->difilt && PLDI_ORI )
00161     {
00162         theta = 0.5 * M_PI * plsc->diorot;
00163         rat   = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) /
00164                 ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm );
00165         rat    = MAX( rat, 1.0 / rat );
00166         rat    = fabs( cos( theta ) ) + rat*fabs( sin( theta ) );
00167         scale /= rat;
00168     }
00169 
00170     if ( plsc->nsuby > 1 )
00171         scale /= sqrt( (double) plsc->nsuby );
00172 
00173     size_chr = 4.0;
00174     size_sym = 4.0;             // All these in virtual plot units
00175     size_maj = 3.0;
00176     size_min = 1.5;
00177 
00178     plsc->chrdef = plsc->chrht = size_chr * scale;
00179     plsc->symdef = plsc->symht = size_sym * scale;
00180     plsc->majdef = plsc->majht = size_maj * scale;
00181     plsc->mindef = plsc->minht = size_min * scale;
00182 }
00183 
00184 //--------------------------------------------------------------------------
00187 void
00188 plP_setsub( void )
00189 {
00190     PLINT ix, iy;
00191 
00192     ix = ( plsc->cursub - 1 ) % plsc->nsubx;
00193     iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx;
00194 
00195     plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx );
00196     plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx );
00197     plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby );
00198     plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby );
00199 
00200     plsc->sppxmi = plP_dcpcx( plsc->spdxmi );
00201     plsc->sppxma = plP_dcpcx( plsc->spdxma );
00202     plsc->sppymi = plP_dcpcy( plsc->spdymi );
00203     plsc->sppyma = plP_dcpcy( plsc->spdyma );
00204 
00205     plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );
00206 }
00207 
00208 //--------------------------------------------------------------------------
00217 void
00218 c_plgspa( PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax )
00219 {
00220     if ( plsc->level < 1 )
00221     {
00222         plabort( "plgspa: Please call plinit first" );
00223         return;
00224     }
00225     *xmin = plP_dcmmx( plsc->spdxmi );
00226     *xmax = plP_dcmmx( plsc->spdxma );
00227     *ymin = plP_dcmmy( plsc->spdymi );
00228     *ymax = plP_dcmmy( plsc->spdyma );
00229 }
00230 
00231 //--------------------------------------------------------------------------
00239 int
00240 plGetCursor( PLGraphicsIn *plg )
00241 {
00242     plP_esc( PLESC_GETC, plg );
00243     return plTranslateCursor( plg );
00244 }
00245 
00246 //--------------------------------------------------------------------------
00254 int
00255 plTranslateCursor( PLGraphicsIn *plg )
00256 {
00257     int window;
00258     c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY,
00259         (PLINT *) &window );
00260     if ( window >= 0 )
00261     {
00262         plg->subwindow = window;
00263         return 1;
00264     }
00265     else
00266         return 0;
00267 }
00268 
00269 //--------------------------------------------------------------------------
00284 void
00285 c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window )
00286 {
00287     int      i;
00288     int      lastwin  = plsc->nplwin - 1;
00289     int      firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 );
00290     PLWindow *w;
00291 
00292     for ( i = lastwin; i >= firstwin; i-- )
00293     {
00294         w = &plsc->plwin[i % PL_MAXWINDOWS];
00295         if ( ( rx >= w->dxmi ) &&
00296              ( rx <= w->dxma ) &&
00297              ( ry >= w->dymi ) &&
00298              ( ry <= w->dyma ) )
00299         {
00300             *wx = w->wxmi + ( rx - w->dxmi ) *
00301                   ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi );
00302 
00303             *wy = w->wymi + ( ry - w->dymi ) *
00304                   ( w->wyma - w->wymi ) / ( w->dyma - w->dymi );
00305 
00306             *window = i;
00307 
00308             return;
00309         }
00310     }
00311     // No valid window found with these relative coordinates.
00312     *wx     = 0.;
00313     *wy     = 0.;
00314     *window = -1;
00315     return;
00316 }

Generated on Wed Oct 12 2011 20:42:22 for PLplot by  doxygen 1.7.1