PLplot  5.10.0
 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 
27 //--------------------------------------------------------------------------
32 void
33 c_pladv( PLINT page )
34 {
35  if ( plsc->level < 1 )
36  {
37  plabort( "pladv: Please call plinit first" );
38  return;
39  }
40 
41  if ( page > 0 && page <= plsc->nsubx * plsc->nsuby )
42  plsc->cursub = page;
43 
44  else if ( page == 0 )
45  {
46  if ( plsc->cursub >= plsc->nsubx * plsc->nsuby )
47  {
48  plP_eop();
49  plP_bop();
50  plsc->cursub = 1;
51  }
52  else
53  plsc->cursub++;
54  }
55  else
56  {
57  plabort( "pladv: Invalid subpage number" );
58  return;
59  }
60 
61  plP_setsub();
62 }
63 
64 //--------------------------------------------------------------------------
67 //
68 void
69 c_plclear( void )
70 {
71  if ( plsc->level < 1 )
72  {
73  plabort( "plclear: Please call plinit first" );
74  return;
75  }
76 
77  if ( plsc->dev_clear )
78  plP_esc( PLESC_CLEAR, NULL );
79  else // driver does not support clear, fill using background color
80 
81  {
82  short x[5], y[5];
83  int ocolor = plsc->icol0;
84 
85  x[0] = x[3] = x[4] = (short) plsc->sppxmi;
86  x[1] = x[2] = (short) plsc->sppxma;
87  y[0] = y[1] = y[4] = (short) plsc->sppymi;
88  y[2] = y[3] = (short) plsc->sppyma;
89  plcol0( 0 );
90  plP_fill( x, y, 5 );
91  plcol0( ocolor );
92  }
93 }
94 
95 //--------------------------------------------------------------------------
98 void
99 c_pleop( void )
100 {
101  if ( plsc->level < 1 )
102  {
103  plabort( "pleop: Please call plinit first" );
104  return;
105  }
106 
107  plsc->cursub = plsc->nsubx * plsc->nsuby;
108  plP_eop();
109 }
110 
111 //--------------------------------------------------------------------------
114 void
115 c_plbop( void )
116 {
117  if ( plsc->level < 1 )
118  {
119  plabort( "plbop: Please call plinit first" );
120  return;
121  }
122  plP_bop();
123  plsc->cursub = 1;
124  plP_setsub();
125 }
126 
127 //--------------------------------------------------------------------------
130 void
132 {
133  PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat;
134 
135 // Subpage checks
136 
137  if ( plsc->nsubx <= 0 )
138  plsc->nsubx = 1;
139  if ( plsc->nsuby <= 0 )
140  plsc->nsuby = 1;
141 
142  plsc->cursub = 0;
143 
144 //
145 // Set default sizes
146 // Global scaling:
147 // Normalize to the page length for more uniform results.
148 // A virtual page length of 200 mm is assumed.
149 // Subpage scaling:
150 // Reduce sizes with plot area (non-proportional, so that character
151 // size doesn't get too small).
152 //
153  scale = 0.5 *
154  ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm +
155  ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0;
156 
157  // Take account of scaling caused by change of orientation
158  if ( plsc->difilt && PLDI_ORI )
159  {
160  theta = 0.5 * M_PI * plsc->diorot;
161  rat = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) /
162  ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm );
163  rat = MAX( rat, 1.0 / rat );
164  rat = fabs( cos( theta ) ) + rat*fabs( sin( theta ) );
165  scale /= rat;
166  }
167 
168  if ( plsc->nsuby > 1 )
169  scale /= sqrt( (double) plsc->nsuby );
170 
171  size_chr = 4.0;
172  size_sym = 4.0; // All these in virtual plot units
173  size_maj = 3.0;
174  size_min = 1.5;
175 
176  plsc->chrdef = plsc->chrht = size_chr * scale;
177  plsc->symdef = plsc->symht = size_sym * scale;
178  plsc->majdef = plsc->majht = size_maj * scale;
179  plsc->mindef = plsc->minht = size_min * scale;
180 }
181 
182 //--------------------------------------------------------------------------
185 void
186 plP_setsub( void )
187 {
188  PLINT ix, iy;
189 
190  ix = ( plsc->cursub - 1 ) % plsc->nsubx;
191  iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx;
192 
193  plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx );
194  plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx );
195  plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby );
196  plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby );
197 
198  plsc->sppxmi = plP_dcpcx( plsc->spdxmi );
199  plsc->sppxma = plP_dcpcx( plsc->spdxma );
200  plsc->sppymi = plP_dcpcy( plsc->spdymi );
201  plsc->sppyma = plP_dcpcy( plsc->spdyma );
202 
203  plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );
204 }
205 
206 //--------------------------------------------------------------------------
215 void
217 {
218  if ( plsc->level < 1 )
219  {
220  plabort( "plgspa: Please call plinit first" );
221  return;
222  }
223  *xmin = plP_dcmmx( plsc->spdxmi );
224  *xmax = plP_dcmmx( plsc->spdxma );
225  *ymin = plP_dcmmy( plsc->spdymi );
226  *ymax = plP_dcmmy( plsc->spdyma );
227 }
228 
229 //--------------------------------------------------------------------------
237 int
239 {
240  plP_esc( PLESC_GETC, plg );
241  return plTranslateCursor( plg );
242 }
243 
244 //--------------------------------------------------------------------------
252 int
254 {
255  int window;
256  c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY,
257  (PLINT *) &window );
258  if ( window >= 0 )
259  {
260  plg->subwindow = window;
261  return 1;
262  }
263  else
264  return 0;
265 }
266 
267 //--------------------------------------------------------------------------
282 void
283 c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window )
284 {
285  int i;
286  int lastwin = plsc->nplwin - 1;
287  int firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 );
288  PLWindow *w;
289 
290  for ( i = lastwin; i >= firstwin; i-- )
291  {
292  w = &plsc->plwin[i % PL_MAXWINDOWS];
293  if ( ( rx >= w->dxmi ) &&
294  ( rx <= w->dxma ) &&
295  ( ry >= w->dymi ) &&
296  ( ry <= w->dyma ) )
297  {
298  *wx = w->wxmi + ( rx - w->dxmi ) *
299  ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi );
300 
301  *wy = w->wymi + ( ry - w->dymi ) *
302  ( w->wyma - w->wymi ) / ( w->dyma - w->dymi );
303 
304  *window = i;
305 
306  return;
307  }
308  }
309  // No valid window found with these relative coordinates.
310  *wx = 0.;
311  *wy = 0.;
312  *window = -1;
313  return;
314 }