PLplot  5.10.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plpage.c
Go to the documentation of this file.
1 // $Id: plpage.c 11973 2011-10-17 21:16:39Z andrewross $
2 //
3 // Copyright (C) 2004 Alan W. Irwin
4 //
5 // This file is part of PLplot.
6 //
7 // PLplot is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU Library General Public License as published
9 // by the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
11 //
12 // PLplot is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Library General Public License for more details.
16 //
17 // You should have received a copy of the GNU Library General Public License
18 // along with PLplot; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 //
21 
26 
27 #include "plplotP.h"
28 
29 //--------------------------------------------------------------------------
34 void
35 c_pladv( PLINT page )
36 {
37  if ( plsc->level < 1 )
38  {
39  plabort( "pladv: Please call plinit first" );
40  return;
41  }
42 
43  if ( page > 0 && page <= plsc->nsubx * plsc->nsuby )
44  plsc->cursub = page;
45 
46  else if ( page == 0 )
47  {
48  if ( plsc->cursub >= plsc->nsubx * plsc->nsuby )
49  {
50  plP_eop();
51  plP_bop();
52  plsc->cursub = 1;
53  }
54  else
55  plsc->cursub++;
56  }
57  else
58  {
59  plabort( "pladv: Invalid subpage number" );
60  return;
61  }
62 
63  plP_setsub();
64 }
65 
66 //--------------------------------------------------------------------------
69 //
70 void
71 c_plclear( void )
72 {
73  if ( plsc->level < 1 )
74  {
75  plabort( "plclear: Please call plinit first" );
76  return;
77  }
78 
79  if ( plsc->dev_clear )
80  plP_esc( PLESC_CLEAR, NULL );
81  else // driver does not support clear, fill using background color
82 
83  {
84  short x[5], y[5];
85  int ocolor = plsc->icol0;
86 
87  x[0] = x[3] = x[4] = (short) plsc->sppxmi;
88  x[1] = x[2] = (short) plsc->sppxma;
89  y[0] = y[1] = y[4] = (short) plsc->sppymi;
90  y[2] = y[3] = (short) plsc->sppyma;
91  plcol0( 0 );
92  plP_fill( x, y, 5 );
93  plcol0( ocolor );
94  }
95 }
96 
97 //--------------------------------------------------------------------------
100 void
101 c_pleop( void )
102 {
103  if ( plsc->level < 1 )
104  {
105  plabort( "pleop: Please call plinit first" );
106  return;
107  }
108 
109  plsc->cursub = plsc->nsubx * plsc->nsuby;
110  plP_eop();
111 }
112 
113 //--------------------------------------------------------------------------
116 void
117 c_plbop( void )
118 {
119  if ( plsc->level < 1 )
120  {
121  plabort( "plbop: Please call plinit first" );
122  return;
123  }
124  plP_bop();
125  plsc->cursub = 1;
126  plP_setsub();
127 }
128 
129 //--------------------------------------------------------------------------
132 void
134 {
135  PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat;
136 
137 // Subpage checks
138 
139  if ( plsc->nsubx <= 0 )
140  plsc->nsubx = 1;
141  if ( plsc->nsuby <= 0 )
142  plsc->nsuby = 1;
143 
144  plsc->cursub = 0;
145 
146 //
147 // Set default sizes
148 // Global scaling:
149 // Normalize to the page length for more uniform results.
150 // A virtual page length of 200 mm is assumed.
151 // Subpage scaling:
152 // Reduce sizes with plot area (non-proportional, so that character
153 // size doesn't get too small).
154 //
155  scale = 0.5 *
156  ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm +
157  ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0;
158 
159  // Take account of scaling caused by change of orientation
160  if ( plsc->difilt && PLDI_ORI )
161  {
162  theta = 0.5 * M_PI * plsc->diorot;
163  rat = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) /
164  ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm );
165  rat = MAX( rat, 1.0 / rat );
166  rat = fabs( cos( theta ) ) + rat*fabs( sin( theta ) );
167  scale /= rat;
168  }
169 
170  if ( plsc->nsuby > 1 )
171  scale /= sqrt( (double) plsc->nsuby );
172 
173  size_chr = 4.0;
174  size_sym = 4.0; // All these in virtual plot units
175  size_maj = 3.0;
176  size_min = 1.5;
177 
178  plsc->chrdef = plsc->chrht = size_chr * scale;
179  plsc->symdef = plsc->symht = size_sym * scale;
180  plsc->majdef = plsc->majht = size_maj * scale;
181  plsc->mindef = plsc->minht = size_min * scale;
182 }
183 
184 //--------------------------------------------------------------------------
187 void
188 plP_setsub( void )
189 {
190  PLINT ix, iy;
191 
192  ix = ( plsc->cursub - 1 ) % plsc->nsubx;
193  iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx;
194 
195  plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx );
196  plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx );
197  plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby );
198  plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby );
199 
200  plsc->sppxmi = plP_dcpcx( plsc->spdxmi );
201  plsc->sppxma = plP_dcpcx( plsc->spdxma );
202  plsc->sppymi = plP_dcpcy( plsc->spdymi );
203  plsc->sppyma = plP_dcpcy( plsc->spdyma );
204 
205  plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );
206 }
207 
208 //--------------------------------------------------------------------------
217 void
219 {
220  if ( plsc->level < 1 )
221  {
222  plabort( "plgspa: Please call plinit first" );
223  return;
224  }
225  *xmin = plP_dcmmx( plsc->spdxmi );
226  *xmax = plP_dcmmx( plsc->spdxma );
227  *ymin = plP_dcmmy( plsc->spdymi );
228  *ymax = plP_dcmmy( plsc->spdyma );
229 }
230 
231 //--------------------------------------------------------------------------
239 int
241 {
242  plP_esc( PLESC_GETC, plg );
243  return plTranslateCursor( plg );
244 }
245 
246 //--------------------------------------------------------------------------
254 int
256 {
257  int window;
258  c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY,
259  (PLINT *) &window );
260  if ( window >= 0 )
261  {
262  plg->subwindow = window;
263  return 1;
264  }
265  else
266  return 0;
267 }
268 
269 //--------------------------------------------------------------------------
284 void
285 c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window )
286 {
287  int i;
288  int lastwin = plsc->nplwin - 1;
289  int firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 );
290  PLWindow *w;
291 
292  for ( i = lastwin; i >= firstwin; i-- )
293  {
294  w = &plsc->plwin[i % PL_MAXWINDOWS];
295  if ( ( rx >= w->dxmi ) &&
296  ( rx <= w->dxma ) &&
297  ( ry >= w->dymi ) &&
298  ( ry <= w->dyma ) )
299  {
300  *wx = w->wxmi + ( rx - w->dxmi ) *
301  ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi );
302 
303  *wy = w->wymi + ( ry - w->dymi ) *
304  ( w->wyma - w->wymi ) / ( w->dyma - w->dymi );
305 
306  *window = i;
307 
308  return;
309  }
310  }
311  // No valid window found with these relative coordinates.
312  *wx = 0.;
313  *wy = 0.;
314  *window = -1;
315  return;
316 }