PLplot  5.11.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
plpage.c
Go to the documentation of this file.
1 // Copyright (C) 2004-2014 Alan W. Irwin
2 //
3 // This file is part of PLplot.
4 //
5 // PLplot is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU Library General Public License as published
7 // by the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version.
9 //
10 // PLplot is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU Library General Public License for more details.
14 //
15 // You should have received a copy of the GNU Library General Public License
16 // along with PLplot; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //
19 
24 
25 #include "plplotP.h"
26 #include "drivers.h"
27 
28 //--------------------------------------------------------------------------
33 void
34 c_pladv( PLINT page )
35 {
36  if ( plsc->level < 1 )
37  {
38  plabort( "pladv: Please call plinit first" );
39  return;
40  }
41 
42  if ( page > 0 && page <= plsc->nsubx * plsc->nsuby )
43  plsc->cursub = page;
44 
45  else if ( page == 0 )
46  {
47  if ( plsc->cursub >= plsc->nsubx * plsc->nsuby )
48  {
49  plP_eop();
50  plP_wait();
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  plP_wait();
112 }
113 
114 //--------------------------------------------------------------------------
117 void
118 c_plbop( void )
119 {
120  if ( plsc->level < 1 )
121  {
122  plabort( "plbop: Please call plinit first" );
123  return;
124  }
125  plP_bop();
126  plsc->cursub = 1;
127  plP_setsub();
128 }
129 
130 //--------------------------------------------------------------------------
133 void
135 {
136  PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat;
137 
138 // Subpage checks
139 
140  if ( plsc->nsubx <= 0 )
141  plsc->nsubx = 1;
142  if ( plsc->nsuby <= 0 )
143  plsc->nsuby = 1;
144 
145  plsc->cursub = 0;
146 
147 //
148 // Set default sizes
149 // Global scaling:
150 // Normalize to the page length for more uniform results.
151 // A virtual page length of 200 mm is assumed.
152 // Subpage scaling:
153 // Reduce sizes with plot area (non-proportional, so that character
154 // size doesn't get too small).
155 //
156  scale = 0.5 *
157  ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm +
158  ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0;
159 
160  // Take account of scaling caused by change of orientation
161  if ( plsc->difilt & PLDI_ORI )
162  {
163  theta = 0.5 * M_PI * plsc->diorot;
164  rat = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) /
165  ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm );
166  rat = MAX( rat, 1.0 / rat );
167  rat = fabs( cos( theta ) ) + rat * fabs( sin( theta ) );
168  scale /= rat;
169  }
170 
171  if ( plsc->nsuby > 1 )
172  scale /= sqrt( (double) plsc->nsuby );
173 
174  size_chr = 4.0;
175  size_sym = 4.0; // All these in virtual plot units
176  size_maj = 3.0;
177  size_min = 1.5;
178 
179  plschr( size_chr * scale, 1.0 );
180  plssym( size_sym * scale, 1.0 );
181  plsmaj( size_maj * scale, 1.0 );
182  plsmin( size_min * scale, 1.0 );
183 }
184 
185 //--------------------------------------------------------------------------
188 void
189 plP_setsub( void )
190 {
191  PLINT ix, iy;
192 
193  ix = ( plsc->cursub - 1 ) % plsc->nsubx;
194  iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx;
195 
196  plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx );
197  plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx );
198  plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby );
199  plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby );
200 
201  plsc->sppxmi = plP_dcpcx( plsc->spdxmi );
202  plsc->sppxma = plP_dcpcx( plsc->spdxma );
203  plsc->sppymi = plP_dcpcy( plsc->spdymi );
204  plsc->sppyma = plP_dcpcy( plsc->spdyma );
205 
206  plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );
207 
208  if ( plsc->plbuf_write )
209  plbuf_setsub( plsc );
210 }
211 
212 //--------------------------------------------------------------------------
221 void
223 {
224  if ( plsc->level < 1 )
225  {
226  plabort( "plgspa: Please call plinit first" );
227  return;
228  }
229  *xmin = plP_dcmmx( plsc->spdxmi );
230  *xmax = plP_dcmmx( plsc->spdxma );
231  *ymin = plP_dcmmy( plsc->spdymi );
232  *ymax = plP_dcmmy( plsc->spdyma );
233 }
234 
235 //--------------------------------------------------------------------------
243 int
245 {
246  plP_esc( PLESC_GETC, plg );
247  return plTranslateCursor( plg );
248 }
249 
250 //--------------------------------------------------------------------------
258 int
260 {
261  int window;
262  c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY,
263  (PLINT *) &window );
264  if ( window >= 0 )
265  {
266  plg->subwindow = window;
267  return 1;
268  }
269  else
270  return 0;
271 }
272 
273 //--------------------------------------------------------------------------
288 void
289 c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window )
290 {
291  int i;
292  int lastwin = plsc->nplwin - 1;
293  int firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 );
294  PLWindow *w;
295 
296  for ( i = lastwin; i >= firstwin; i-- )
297  {
298  w = &plsc->plwin[i % PL_MAXWINDOWS];
299  if ( ( rx >= w->dxmi ) &&
300  ( rx <= w->dxma ) &&
301  ( ry >= w->dymi ) &&
302  ( ry <= w->dyma ) )
303  {
304  *wx = w->wxmi + ( rx - w->dxmi ) *
305  ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi );
306 
307  *wy = w->wymi + ( ry - w->dymi ) *
308  ( w->wyma - w->wymi ) / ( w->dyma - w->dymi );
309 
310  *window = i;
311 
312  return;
313  }
314  }
315  // No valid window found with these relative coordinates.
316  *wx = 0.;
317  *wy = 0.;
318  *window = -1;
319  return;
320 }