File: plpage.c

package info (click to toggle)
plplot 5.15.0%2Bdfsg2-19
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 31,484 kB
  • sloc: ansic: 79,703; xml: 28,583; cpp: 20,033; ada: 19,456; tcl: 12,081; f90: 11,431; ml: 7,276; java: 6,863; python: 6,792; sh: 3,274; perl: 828; lisp: 75; makefile: 74; sed: 34; fortran: 6
file content (320 lines) | stat: -rw-r--r-- 9,072 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
// Copyright (C) 2004-2014 Alan W. Irwin
//
// This file is part of PLplot.
//
// PLplot is free software; you can redistribute it and/or modify
// it under the terms of the GNU Library General Public License as published
// by the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// PLplot is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Library General Public License for more details.
//
// You should have received a copy of the GNU Library General Public License
// along with PLplot; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//

//! @file
//!
//! Page/subpage handling routines.
//!

#include "plplotP.h"
#include "drivers.h"

//--------------------------------------------------------------------------
//! Advance to subpage "page" or to the next page if "page" = 0.
//!
//! @param page Subpage identifier or 0
//!
void
c_pladv( PLINT page )
{
    if ( plsc->level < 1 )
    {
        plabort( "pladv: Please call plinit first" );
        return;
    }

    if ( page > 0 && page <= plsc->nsubx * plsc->nsuby )
        plsc->cursub = page;

    else if ( page == 0 )
    {
        if ( plsc->cursub >= plsc->nsubx * plsc->nsuby )
        {
            plP_eop();
            plP_wait();
            plP_bop();
            plsc->cursub = 1;
        }
        else
            plsc->cursub++;
    }
    else
    {
        plabort( "pladv: Invalid subpage number" );
        return;
    }

    plP_setsub();
}

//--------------------------------------------------------------------------
//! Clear current subpage.  Subpages can be set with pladv before
//! calling plclear. Not all drivers support this.
//
void
c_plclear( void )
{
    if ( plsc->level < 1 )
    {
        plabort( "plclear: Please call plinit first" );
        return;
    }

    if ( plsc->dev_clear )
        plP_esc( PLESC_CLEAR, NULL );
    else   // driver does not support clear, fill using background color

    {
        short x[5], y[5];
        int   ocolor = plsc->icol0;

        x[0] = x[3] = x[4] = (short) plsc->sppxmi;
        x[1] = x[2] = (short) plsc->sppxma;
        y[0] = y[1] = y[4] = (short) plsc->sppymi;
        y[2] = y[3] = (short) plsc->sppyma;
        plcol0( 0 );
        plP_fill( x, y, 5 );
        plcol0( ocolor );
    }
}

//--------------------------------------------------------------------------
//! End current page.
//!
void
c_pleop( void )
{
    if ( plsc->level < 1 )
    {
        plabort( "pleop: Please call plinit first" );
        return;
    }

    plsc->cursub = plsc->nsubx * plsc->nsuby;
    plP_eop();
    plP_wait();
}

//--------------------------------------------------------------------------
//! Start new page. Should only be used with pleop().
//!
void
c_plbop( void )
{
    if ( plsc->level < 1 )
    {
        plabort( "plbop: Please call plinit first" );
        return;
    }
    plP_bop();
    plsc->cursub = 1;
    plP_setsub();
}

//--------------------------------------------------------------------------
//! Set up plot parameters according to the number of subpages.
//!
void
plP_subpInit( void )
{
    PLFLT scale, size_chr, size_sym, size_maj, size_min, theta, rat;

// Subpage checks

    if ( plsc->nsubx <= 0 )
        plsc->nsubx = 1;
    if ( plsc->nsuby <= 0 )
        plsc->nsuby = 1;

    plsc->cursub = 0;

//
// Set default sizes
// Global scaling:
//	Normalize to the page length for more uniform results.
//      A virtual page length of 200 mm is assumed.
// Subpage scaling:
//	Reduce sizes with plot area (non-proportional, so that character
//	size doesn't get too small).
//
    scale = 0.5 *
            ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm +
              ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm ) / 200.0;

    // Take account of scaling caused by change of orientation
    if ( plsc->difilt & PLDI_ORI )
    {
        theta = 0.5 * M_PI * plsc->diorot;
        rat   = ( ( plsc->phyxma - plsc->phyxmi ) / plsc->xpmm ) /
                ( ( plsc->phyyma - plsc->phyymi ) / plsc->ypmm );
        rat    = MAX( rat, 1.0 / rat );
        rat    = fabs( cos( theta ) ) + rat * fabs( sin( theta ) );
        scale /= rat;
    }

    if ( plsc->nsuby > 1 )
        scale /= sqrt( (double) plsc->nsuby );

    size_chr = 4.0;
    size_sym = 4.0;             // All these in virtual plot units
    size_maj = 3.0;
    size_min = 1.5;

    plschr( size_chr * scale, 1.0 );
    plssym( size_sym * scale, 1.0 );
    plsmaj( size_maj * scale, 1.0 );
    plsmin( size_min * scale, 1.0 );
}

//--------------------------------------------------------------------------
//! Set up the subpage boundaries according to the current subpage selected.
//!
void
plP_setsub( void )
{
    PLINT ix, iy;

    ix = ( plsc->cursub - 1 ) % plsc->nsubx;
    iy = plsc->nsuby - ( plsc->cursub - 1 ) / plsc->nsubx;

    plsc->spdxmi = (PLFLT) ( ix ) / (PLFLT) ( plsc->nsubx );
    plsc->spdxma = (PLFLT) ( ix + 1 ) / (PLFLT) ( plsc->nsubx );
    plsc->spdymi = (PLFLT) ( iy - 1 ) / (PLFLT) ( plsc->nsuby );
    plsc->spdyma = (PLFLT) ( iy ) / (PLFLT) ( plsc->nsuby );

    plsc->sppxmi = plP_dcpcx( plsc->spdxmi );
    plsc->sppxma = plP_dcpcx( plsc->spdxma );
    plsc->sppymi = plP_dcpcy( plsc->spdymi );
    plsc->sppyma = plP_dcpcy( plsc->spdyma );

    plP_sclp( plsc->sppxmi, plsc->sppxma, plsc->sppymi, plsc->sppyma );

    if ( plsc->plbuf_write )
        plbuf_setsub( plsc );
}

//--------------------------------------------------------------------------
//! Get subpage boundaries in absolute coordinates (mm from bottom
//! left-hand corner of page).
//!
//! @param xmin Pointer to PLFLT containing minimum x boundary after call
//! @param xmax Pointer to PLFLT containing maximum x boundary after call
//! @param ymin Pointer to PLFLT containing minimum y boundary after call
//! @param ymax Pointer to PLFLT containing maximum y boundary after call
//!
void
c_plgspa( PLFLT *xmin, PLFLT *xmax, PLFLT *ymin, PLFLT *ymax )
{
    if ( plsc->level < 1 )
    {
        plabort( "plgspa: Please call plinit first" );
        return;
    }
    *xmin = plP_dcmmx( plsc->spdxmi );
    *xmax = plP_dcmmx( plsc->spdxma );
    *ymin = plP_dcmmy( plsc->spdymi );
    *ymax = plP_dcmmy( plsc->spdyma );
}

//--------------------------------------------------------------------------
//! Wait for graphics input event and translate to world coordinates.
//!
//! @author Paul Casteels.
//! @param plg Pointer to PLGraphicsIn
//! @return 0 if no translation to world coordinates is possible.
//! @see PLGraphicsIn
//!
PLINT
plGetCursor( PLGraphicsIn *plg )
{
    plP_esc( PLESC_GETC, plg );
    return plTranslateCursor( plg );
}

//--------------------------------------------------------------------------
//! Translates cursor position from relative device coordinates to world
//! coordinates.
//!
//! @author Paul Casteels, modified by Alan W. Irwin
//! @param plg Pointer to PLGraphicsIn
//! @return 0 if no translation to world coordinates is possible.
//!
PLINT
plTranslateCursor( PLGraphicsIn *plg )
{
    int window;
    c_plcalc_world( plg->dX, plg->dY, &plg->wX, &plg->wY,
        (PLINT *) &window );
    if ( window >= 0 )
    {
        plg->subwindow = window;
        return 1;
    }
    else
        return 0;
}

//--------------------------------------------------------------------------
//! Calculate world coordinates wx, and wy from relative device
//! coordinates, rx and ry.  Also, return the window index for which
//! the world coordinates are valid. window is set to -1 and wx and wy
//! to 0. if rx and ry do not correspond to valid world coordinates
//! for any currently existing window.
//!
//! @author Paul Casteels, modified by Alan W. Irwin.
//! @param rx Relative x device coordinates
//! @param ry Relative y device coordinates
//! @param wx Pointer to x world coordinate (after call)
//! @param wy Pointer to y world coordinate (after call)
//! @param window Pointer index of window for which the world coordinates
//! are valid
//!
void
c_plcalc_world( PLFLT rx, PLFLT ry, PLFLT *wx, PLFLT *wy, PLINT *window )
{
    int      i;
    int      lastwin  = plsc->nplwin - 1;
    int      firstwin = MAX( plsc->nplwin - PL_MAXWINDOWS, 0 );
    PLWindow *w;

    for ( i = lastwin; i >= firstwin; i-- )
    {
        w = &plsc->plwin[i % PL_MAXWINDOWS];
        if ( ( rx >= w->dxmi ) &&
             ( rx <= w->dxma ) &&
             ( ry >= w->dymi ) &&
             ( ry <= w->dyma ) )
        {
            *wx = w->wxmi + ( rx - w->dxmi ) *
                  ( w->wxma - w->wxmi ) / ( w->dxma - w->dxmi );

            *wy = w->wymi + ( ry - w->dymi ) *
                  ( w->wyma - w->wymi ) / ( w->dyma - w->dymi );

            *window = i;

            return;
        }
    }
    // No valid window found with these relative coordinates.
    *wx     = 0.;
    *wy     = 0.;
    *window = -1;
    return;
}