File: grap_pic.cc

package info (click to toggle)
grap 1.39-2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 820 kB
  • ctags: 584
  • sloc: cpp: 3,024; yacc: 1,063; lex: 1,004; makefile: 187; sh: 168; awk: 5
file content (912 lines) | stat: -rw-r--r-- 24,195 bytes parent folder | download
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
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <stdexcept>
#include "grap.h"
#include "grap_data.h"
#include "grap_draw.h"
#include "grap_pic.h"

// This file is (c) 1998-2001 Ted Faber (faber@lunabase.org) see COPYRIGHT
// for the full copyright and limitations of liabilities.

// Convert the abstract types to Pictypes and draw them.  These are
// called from for_each.  These are declared outside the pic classes
// to keep g++ 2.7.3 happy.
template <class FROM, class TO>
class draw_f :
    public unary_function<FROM *, int> {
    frame *f;
public:
    draw_f(frame *fr) : f(fr) { }
    int operator()(FROM *ds) {
	TO p(*ds);
	p.draw(f);
	return 0;
    }
};

// Simpler declarations
typedef draw_f<DisplayString, PicDisplayString> draw_string_f;
typedef draw_f<tick, Pictick> draw_tick_f;
typedef draw_f<grid, Picgrid> draw_grid_f;

// A little helper function - tells if a DisplayString * points to a string
// with the clipped attribute.  In an anonymous namespace so no one else has to
// see it.
namespace {
    bool clipped(DisplayString *d) { return d->clip; }
}

extern bool compat_mode;

void Picgraph::init(string *n /* =0 */, string* p /* =0 */ ) {
    // Start a new graph, but maybe not a new block.
    
    if ( frame_queued ) base = 0;
    graph::init(n, p);	// clear the base classes parameters

    if ( !base ) 
	base = pframe = new Picframe;
    if ( p ) pos = new string(*p);
    frame_queued = false;
}
	
void Picgraph::draw(frame *) {
    // Do the work of drawing the current graph.
    displayer_f displayer(pframe); 	// Call draw on the object.  This is
                                        // an embedded class of graph.
    if ( visible ) {
	if ( !graphs++ ) {
	    cout << ".PS";
	    if (ps_param ) {
		cout << *ps_param;
		delete ps_param;
		ps_param = 0;
	    }
	    cout << endl;
	}

	// if we have a name, use it
	if ( name ) 
	    cout << *name << ": ";

	// The graph itself
	cout << "[" << endl;

	for_each(coords.begin(), coords.end(), addmargin);
	// put out the xy_gg mpic macros
	for (coordinateDictionary::iterator ci = coords.begin();
	     ci != coords.end();
	     ci++) {
	    Piccoord pc(*(*ci).second);
	    displayer(&pc);
	}
	for_each(objs.begin(), objs.end(), displayer);
	cout << "]";

	    // Positioning info relative to another graph in this block
	if ( pos ) {
	    cout << " " << *pos << endl;
	    delete pos;
	    pos = 0;
	}
	else cout << endl;

    }

}


void PicDisplayString::draw(frame *) {
// Draw a display string.  Basically just a straight translation into
// pic/troff idioms.

    cout << '"';
    if ( size ) {
	if ( relsz ) {
	    char relchar = ( size > 0 ) ? '+' : '-';
	    size = fabs(size);
	    if ( compat_mode ) {
		cout << "\\s" << relchar;
		cout << ((size > 9) ? "(" : "") << size;
	    }
	    else {
		cout << "\\s[" << relchar << size << "]";
	    }
	}
	else {
	    // double digit size changes need the ( using classic troff.  Groff
	    // allows a general [] syntax, that we use if available ).
	    if ( compat_mode ) 
		cout << "\\s" << ((size > 9) ? "(" : "") << size;
	    else
		cout << "\\s[" << size << "]";
	}
    }
    if ( color && !compat_mode ) {
	unquote(color);
	cout << "\\m[" << *color << "]";
    }
    
    unquote(this);
    cout << *(string*)this;

    if ( color && !compat_mode ) cout << "\\m[]";
    if ( size ) cout << "\\s" << 0 ;
    cout << "\" ";

    if ( j & (int) ljust ) cout << "ljust ";
    if ( j & (int) rjust ) cout << "rjust ";
    if ( j & (int) above ) cout << "above ";
    if ( j & (int) below ) cout << "below ";
    if ( j & (int) aligned ) cout << "aligned ";
}


void Picframe::frame_line(double x2, double y2, sides s) {
// straightforward line drawing of one frame line

    switch (s) {
	case left_side:
	    cout << "Left: ";
	    break;
	case right_side:
	    cout << "Right: ";
	    break;
	case top_side:
	    cout << "Top: ";
	    break;
	case bottom_side:
	    cout << "Bottom: ";
	    break;
    }
    cout << "line ";
    switch (desc[s].ld) {
	case invis:
	    cout << "invis ";
	    break;
	case solid:
	default:
	    break;
	case dotted:
	    cout << "dotted ";
	    if ( desc[s].param )
		cout << desc[s].param << " ";
	    break;
	case dashed:
	    cout << "dashed ";
	    if ( desc[s].param )
		cout << desc[s].param << " ";
	    break;
    }
    if ( !compat_mode ) { 
	if ( desc[s].color ) cout << " color " << *desc[s].color << " " ;
	if ( desc[s].thick ) cout << " thickness " << desc[s].thick << " " ;
    }
    cout << "right " << x2 << " up " << y2 << endl;
}

void Picframe::label_line(sides s) {
// Label a graph side.  We rely heavily on pic tricks here.  The C++
// is straightforward.

    // Functor to convert a DisplayString to a PicdisplayString and print it
    draw_string_f draw_string(this);
    double dx, dy; // Used to place the alignment line relative to the axis
    shiftlist::const_iterator csi;

    switch (s) {
	case left_side:
	    dx = -0.4; dy = 0;
	    break;
	case right_side:
	    dx = 0.4; dy = 0;
	    break;
	case top_side:
	    dx = 0; dy = 0.4;
	    break;
	case bottom_side:
	    dx = 0; dy = -0.4;
	    break;
	default: // to keep the compiler quiet
	    dx = dy = 0;
	    break;
    }

    for (csi = lshift[s]->begin(); csi != lshift[s]->end(); csi++) {
	switch ((*csi)->dir) {
	    case left_side:
		dx -= (*csi)->param;
		break;
	    case right_side:
		dx += (*csi)->param;
		break;
	    case top_side:
		dy += (*csi)->param;
		break;
	    case bottom_side:
		dy -= (*csi)->param;
		break;
	}
    }

    // DWB grap did not put the whitespace around for unlabelled sizes of the
    // graph, so omit that space if in compatibility mode.
    if ( compat_mode && label[s]->empty() ) return;
    cout << "line invis ";

    // draw all the labels
    for_each(label[s]->begin(), label[s]->end(), draw_string);

    switch (s) {
	case left_side:
	    cout << "from Frame.Left.start + (" << dx << ", " << dy << ") " ;
	    cout << "to Frame.Left.end + (" << dx << ", " << dy << ") " ;
	    break;
	case right_side:
	    cout << "from Frame.Right.start + (" << dx << ", " << dy << ") " ;
	    cout << "to Frame.Right.end + (" << dx <<  ", " << dy << ") " ;
	    break;
	case bottom_side:
	    cout << "from Frame.Bottom.end + (" << dx <<  ", " << dy << ") " ;
	    cout << "to Frame.Bottom.start + (" << dx <<  ", " << dy << ") " ;
	    break;
	case top_side:
	    cout << "from Frame.Top.start + (" << dx <<  ", " << dy << ") " ;
	    cout << "to Frame.Top.end + (" << dx << ", " << dy << ") " ;
	    break;
	default:
	    break;
    }
    cout << endl;
}

void Picframe::autoguess(sides sd, double &idx, double& dir, double& lim,
			 double &ts, int& ls, coord *c) {
// Calculate a reasonable placement of tickmarks if the user has not
// specified one.  We aim for 5.  The algorithm is heuristic.
    
    double lo, hi;	// Low and high tickmarks
    double range;	// the range of the coordinate system

    // determine the range of the axes
    
    if ( sd == bottom_side || sd == top_side ) {
	lo = c->xmin;
	hi = c->xmax;
	ls = (c->logscale & x_axis);
    } else {
	lo = c->ymin;
	hi = c->ymax;
	ls = (c->logscale & y_axis);
    }

    // Make our ticksize guess
    if ( !ls ) {
	range = fabs(hi - lo);
	
	ts = pow(10,floor(log10(range)));
	while ( range/ts > 4 ) ts *= 2;
	while ( range/ts < 3 ) ts /=2;
	idx = ts * ceil(lo/ts);
    } else {
	idx = pow(10,floor(log10(lo)));
    }

    // On machines with signed 0 representations, this ensures that
    // tickmarks have a 0 label (not a -0).  See math(3).

    if ( idx == -0.0 ) idx = 0.0;
    
    // Are ticks increasing or decreasing?
    if ( hi - lo < 0 ) dir = -1;
    else dir = 1;

    lim = hi;
}


void Picframe::addautoticks(sides sd) {
// Place ticks in accordance with the parameters returned by autoguess
    double ts;		// The tick size (for linear axes)
    double dir, idx;	// The direction of ticks and an index value
    double hi;		// the tick limit
    int ls;		// is this a logscale axis?
    tick *t;		// Temporary tick value

    if ( tickdef[sd].size == 0 ) return;

    autoguess(sd, idx, dir, hi, ts, ls, tickdef[sd].c);

    // We use EPSILON in loops
    while ( idx - hi < EPSILON*dir ) {
	t = new tick(idx,tickdef[sd].size,sd,0, &tickdef[sd].shift,
		     tickdef[sd].c);
	if ( tickdef[sd].prt)
	    t->prt = new DisplayString(idx,tickdef[sd].prt);
	    //t->prt = dblString(idx,tickdef[sd].prt);
	tks.push_back(t);
	if ( ls ) idx *= 10;
	else idx += ts;
    }
}
    
void Picframe::addautogrids(sides sd) {
// Place grids in accordance with the parameters returned by autoguess
    double ts;
    double dir, idx;
    double hi;
    int ls;
    grid *g;

    if ( griddef[sd].desc.ld == def ) return;

    autoguess(sd, idx, dir, hi, ts, ls, griddef[sd].c);

    // We use EPSILON in loops
    while ( idx - hi < EPSILON*dir ) {
	g = new grid(idx,&griddef[sd].desc,sd,0,
		     &griddef[sd].shift, griddef[sd].c);
	if ( griddef[sd].prt)
	    // g->prt = dblString(idx,griddef[sd].prt);
	    g->prt = new DisplayString(idx,griddef[sd].prt);
	gds.push_back(g);
	if ( ls ) idx *= 10;
	else idx += ts;
    }
}    

void Picframe::draw(frame *) {
// Draw the frame.  Autotick if necessary and draw the axes and
// tickmarks.  Straightforward application of the helpers above.  The
// result is a frame that is labelled for pic placement of other
// graphs in the same block.
    
    // functors to draw ticks and grids out of the lists.  

    draw_tick_f draw_tick(this);
    draw_grid_f draw_grid(this);

    cout << "Frame: [" << endl;
    cout << "Origin: " << endl;
    frame_line(0,ht,left_side);
    frame_line(wid,0,top_side);
    frame_line(0,-ht,right_side);
    frame_line(-wid,0,bottom_side);
    cout << "]" << endl;

    for ( int i = 0; i < 4 ; i++ ) {
	if ( label[(sides)i] )
	    label_line((sides)i);
	addautoticks((sides)i);
	addautogrids((sides)i);
    }

    for_each(tks.begin(), tks.end(), draw_tick);
    for_each(gds.begin(), gds.end(), draw_grid);
}

bool Piclinesegment::clipx(double& x1, double& y1, double& x2, double& y2) {
// Clip the line to x = 0 and x = 1.  We use the parametric
// representation of the line for simplicity of calculation.  This
// gets called with the coordinates reversed to do the y-axis clip.

    // the line is p + tv where x1, y1 is t==0 and x2, y2 is t==1

    double px = x1;		// Point coordinate
    double py = y1;		// Point coordinate
    double vx = x2 - x1;	// vector component
    double vy = y2 - y1;	// vector component
    double t;			// The parameter


    // The line is parallel to the x axis.  It's either all valid or
    // all invalid.  We use EPSILON again here to be conservative.
    if ( vx > -EPSILON && vx < EPSILON )
	if ( inbox(px) ) return true;
	else return false;

    // Do the x = 0 intercept

    t = -px / vx;

    // The semantics of inbox here mean that the line has been
    // clipped.  The intersection with x = 0 is between x1, y1 (t==0)
    // and x2, y2 (t==1).
    if ( inbox(t) ) {
	// This is the zero intercept, and one point has been clipped,
	// so if the first hasn't been clipped, the second must have.
	// We recalculate the parametric representation so we can
	// repeat the clip for x == 1.  We use EPSILON here because we have to
	// use it by definition in the t==1 half.
	if ( px < EPSILON ) {
	    x1 = px + t * vx;
	    y1 = py + t * vy;
	    px = x1;
	    py = y1;
	}
	else {
	    x2 = px + t * vx;
	    y2 = py + t * vy;
	}
	vx = x2 - x1;
	vy = y2 - y1;
    }
    // repeat for 1

    t = (1 - px) / vx;
	    
    // The semantics of inbox here mean that the line has been
    // clipped.
    if ( inbox(t) ) {
	// This is the 1 intercept, and one point has been clipped,
	// so if the first hasn't been clipped, the second must have.
	if ( px > 1 - EPSILON ) {
	    x1 = px + t * vx;
	    y1 = py + t * vy;
	}
	else {
	    x2 = px + t * vx;
	    y2 = py + t * vy;
	}
    }
    // If both x points are clipped to inside the box, we have a line,
    // otherwise, the whole line is invalid.
    return inbox(x1) && inbox(x2);
}    
    
bool Piclinesegment::clip(double& x1, double& y1, double& x2, double& y2) {
// If all 4 points are in the frame, return true.  If not call
// clip twice to clip the lines, and return true only if both
// clips return valid lines.  There is a little sleight of hand
// there: the && guarantees that we only keep clipping while there
// is a line to clip.

    if ( inbox(x1) && inbox(x2) && inbox(y1) && inbox(y2) ) return true;
    else return clipx(x1, y1, x2, y2) && clipx(y1, x1, y2, x2);
}

void Piclinesegment::draw(frame *f) {
// Draw this line segment.  Clip the line segment according to the
// point's coordinates, then put them into the graph.  There are some
// details to laying out the styles and poltting strings correctly.
    double lastx, lasty;		// The last point plotted (if any)
    double x,y;				// The current point's coordinates
    double lastcx, lastcy;		// The last point plotted post clipping
    double cx,cy;			// The current point post clipping

    try {
	x = to.c->map(to.x,x_axis);
	y = to.c->map(to.y,y_axis);
    }
    catch (range_error &e) {
	cerr << "Unable to map point: (" << to.x << ", " << to.y 
	     << ") : " << e.what() << endl;
	return;
    }

    if ( from ) {
	try { 
	    lastcx = from->c->map(from->x, x_axis);
	    lastcy = from->c->map(from->y, y_axis);
	}
	catch (range_error &e) {
	    cerr << "Unable to map point: (" << to.x << ", " << to.y 
		 << ") : " << e.what() << endl;
	    return;
	}
    }
    else {
	lastx = lasty = 0.0;
    }
	
    cx = x;
    cy = y;
    if ( !from || clip(lastcx, lastcy, cx, cy) ) {
	// If clipping has left us a (partial) line to draw, do
	// so.  This also is invoked on the first point of a line.
	    
	if ( !from ) {
	    if ( inbox(x) && inbox(y) )
		cout << "move to Frame.Origin + (" << x * f->wid << ", "
		     << y * f->ht << ")" << endl;
	}
	else {
	    // Chop off the arrowhead if the line is clipped
	    if ( arrow && inbox(x) && inbox(y) ) cout << "arrow ";
	    else cout << "line ";
	    switch (desc.ld) {
		case invis:
		    cout << "invis ";
		    break;
		case solid:
		default:
		    break;
		case dotted:
		    cout << "dotted ";
		    if ( desc.param ) cout << desc.param << " ";
		    break;
		case dashed:
		    cout << "dashed ";
		    if ( desc.param ) cout << desc.param << " ";
		    break;
	    }
	    if ( !compat_mode ) {
		if ( desc.color ) cout << " color " << *desc.color << " " ;
		if ( desc.thick ) cout << " thickness " << desc.thick << " " ;
	    }
	    cout << "from Frame.Origin + (" << lastcx * f->wid << ", "
		 << lastcy * f->ht << ") ";
	    cout << "to Frame.Origin + (" << cx * f->wid << ", "
		 << cy * f->ht << ")" << endl;
	}
	// if a plot string has been specified and the point has
	// not been clipped, put the plotstring out.
	if ( plotstr && inbox(x) && inbox(y) ) {
	    PicDisplayString pstr(*plotstr);
	    pstr.draw(f);
	    if ( !from ) 
		cout << " at Frame.Origin + (" << x * f->wid << ", "
		     << y * f->ht << ")" << endl;
	    else cout << " at last line.end" << endl;
	}
    }
}

void Pictick::draw(frame *f) {
// Actually draw a tick mark.  Map it into the appropriate coordinate
// space and draw and label the line.  The translation from data
// structure to pic is straightforward.
    
    double a,b;	// x and y offsets from the origin
    char *dir;	// Direction of the tick mark
    char *just;	// placement of the label relative to the end of the tick
    Picshiftdraw sd(cout); // Functor to put out multiple tick shifts

    try {
	switch (side) {
	    default:
	    case left_side:
		a = 0;
		b = c->map(where,y_axis);
		dir = "left";
		just = "rjust";
		break;
	    case right_side:
		a = 1;
		b = c->map(where,y_axis);
		dir = "right";
		just = "ljust";
		break;
	    case top_side:
		a = c->map(where,x_axis);
		b = 1;
		dir = "up";
		just = "above";
		break;
	    case bottom_side:
		a  = c->map(where,x_axis);
		b = 0;
		dir = "down";
		just = "below";
		break;
	}
    }
    catch (range_error& e) {
	cerr << "failed to map tick value: " << where << ": " 
	     << e.what() << endl;
	return;
    }
    // EPSLIONS for floating point weirdness
    if ( a < -EPSILON || a > 1+EPSILON ) return;
    else a *= f->wid;
    if ( b < -EPSILON || b > 1+EPSILON ) return;
    else b *= f->ht;
    cout << "line from Frame.Origin + (" << a << ", " << b;
    cout << ") then " << dir << " ";
    cout << size << endl;
    if ( prt ) {
	double dist;
	if ( size > 0 ) dist = 1.2 * size;
	else dist = 0;
	
	cout << "move from Frame.Origin + (" << a << ", " << b;
	cout << ") then " << dir << " ";
	cout << dist << endl;

	for_each(shift.begin(), shift.end(), sd);

	quote(prt);
	PicDisplayString pprt(*prt);
	pprt.draw(f);
	cout << " " << just << " at Here" << endl;
    }
}
    
void Picgrid::draw(frame *f) {
// Draw a grid line.  As usual very similar to a tick.
    double a,b;
    double len;
    char *dir;
    Picshiftdraw sd(cout); // Functor to put out multiple tick shifts

    try { 
	switch (side) {
	    default:
	    case left_side:
		a = 0;
		b = c->map(where,y_axis);
		dir = "right";
		len = f->wid;
		break;
	    case right_side:
		a = 1;
		b = c->map(where,y_axis);
		dir = "left";
		len = f->wid;
		break;
	    case top_side:
		a = c->map(where,x_axis);
		b = 1;
		dir = "down";
		len = f->ht;
		break;
	    case bottom_side:
		a  = c->map(where,x_axis);
		b = 0;
		dir = "up";
		len = f->ht;
		break;
	}
    }
    catch (range_error& e) {
	cerr << "failed to map grid value: " << where << ": " 
	     << e.what() << endl;
	return;
    }
    if ( a < 0 || a > 1 ) return;
    else a *= f->wid;
    if ( b < 0 || b > 1 ) return;
    else b *= f->ht;
    cout << "line ";
    switch (desc.ld) {
	case invis:
	    cout << "invis ";
	    break;
	case solid:
	default:
	    break;
	case dotted:
	    cout << "dotted ";
	    if ( desc.param )
		cout << desc.param << " ";
	    break;
	case dashed:
	    cout << "dashed ";
	    if ( desc.param )
		cout << desc.param << " ";
	    break;
    }
    if ( !compat_mode ) {
	if ( desc.color ) cout << " color " << *desc.color << " ";
	if ( desc.thick ) cout << " thickness " << desc.thick << " ";
    }
    cout << "from Frame.Origin + (" << a << ", " << b;
    cout << ") then " << dir << " ";
    cout << len << endl;
    if ( prt ) {
	cout << "move from Frame.Origin + (" << a << ", " << b;
	cout << ") then " << dir << " ";
	cout << -0.125 << endl;

	for_each(shift.begin(), shift.end(), sd);

	quote(prt);
	PicDisplayString pprt(*prt);
	pprt.draw(f);
	cout << " at Here" << endl;
    }
}
    
void Piccircle::draw(frame *f) {
// Plot a circle.  Strightforward.
    double x,y;	// To transform the point into device coordinates

    try {
	x = center.c->map(center.x,x_axis);
	y = center.c->map(center.y,y_axis);
    }
    catch (range_error& e) {
	cerr << "Unable to map circle at (" << center.x << ", " 
	     << center.y << ") into " << "log coordinates: " 
	     << e.what() << endl;
	return;
    }
   
    // Again, EPSILON is correct because it's needed for the 1+ and symmetry.
    if ( x > 1+EPSILON || x < 0-EPSILON ) {
	cerr << "Circle outside coordinates:" << center.x << ", ";
	cerr << center.y << endl;
	return;
    }
    if ( y > 1+EPSILON || y < 0-EPSILON ) {
	cerr << "Circle outside coordinates:" << center.x << ", ";
	cerr << center.y << endl;
	return;
    }
    x *= f->wid;
    y *= f->ht;
    cout << "circle at Frame.Origin + (" << x << ", " << y << ")";
    cout << " rad " << rad ;
    switch (ld.ld) {
	case invis:
	    cout << " invis ";
	    break;
	case solid:
	default:
	    break;
	case dotted:
	    cout << " dotted ";
	    if ( ld.param )
		cout << ld.param << " ";
	    break;
	case dashed:
	    cout << " dashed ";
	    if ( ld.param )
		cout << ld.param << " ";
	    break;
    }
    if ( !compat_mode ) {
	if ( ld.fillcolor ) {
	    // fillcolor takes precedence over fill - if fillcolor is not
	    // null, we draw one box filled with that color, and then a
	    // second unfilled one in color (black is none specified)

	    ld.fill = 0;
	    cout << " shaded " << *ld.fillcolor << " ";
	}	

	// Draw the circle with appropriate line style, fill, and color
	if ( ld.color ) cout << " outline " << *ld.color << " ";
	if ( ld.thick ) cout << " thick " << ld.thick << " " ;
    }

    if ( ld.fill ) cout << " fill " << ld.fill;
    cout << endl;
}

void Picbox::draw(frame *f) {
    // Plot the box.  If there is a fill color, plot it twice so that
    // the box and edge can be different colors
    double x1,y1, x2,y2;	// The box edges in device coords.
    double ht, wid;		// height and width in device units (inches)

    try {
    x1 = p1.c->map(p1.x,x_axis);
    y1 = p1.c->map(p1.y,y_axis);
    x2 = p2.c->map(p2.x,x_axis);
    y2 = p2.c->map(p2.y,y_axis);
    } 
    catch (range_error& e) {
	cerr << "Unable to map box [(" << x1 << ", " << y1 << "), ("
	     << x2 << ", " << y2 << ")] into logscale : " << e.what() << endl;
	return;
    }

    // make (x1,y1) upper right and (x2,y2) lower left
    if ( x1 < x2 ) swap(x1,x2);
    if ( y1 < y2) swap(y1,y2);

    // Clip the box

    // If the box is entirely out of frame, ignore it.  EPSILON for 1+ and
    // symmetry.
    if ( (x1 > 1+EPSILON && x2 > 1+EPSILON) ||
	 (x1 <-EPSILON && x2 < -EPSILON ) ) return;
    if ( (y1 > 1+EPSILON && y2 > 1+EPSILON) ||
	 (y1 <-EPSILON && y2 < -EPSILON ) ) return;

    // Box is at least partially in frame - clip it
    if ( x1 > 1+EPSILON) x1 = 1;
    if ( y1 > 1+EPSILON) y1 = 1;
    if ( x2 < -EPSILON) x2 = 0;
    if ( y2 < -EPSILON) y2 = 0;

    x1 *= f->wid;
    y1 *= f->ht;
    x2 *= f->wid;
    y2 *= f->ht;

    wid = fabs(x1-x2);
    ht = fabs(y1-y2);

    cout << "box ht " << ht << " wid " << wid ;
    cout << " with .ne at Frame.Origin + (" << x1 << ", " << y1 << ")";
    
    switch (ld.ld) {
	case invis:
	    cout << " invis ";
	    break;
	case solid:
	default:
	    break;
	case dotted:
	    cout << " dotted ";
	    if ( ld.param )
		cout << ld.param << " ";
	    break;
	case dashed:
	    cout << " dashed ";
	    if ( ld.param )
		cout << ld.param << " ";
	    break;
    }

    if ( !compat_mode ) {
	if ( ld.fillcolor ) {
	    // fillcolor takes precedence over fill - if fillcolor is not
	    // null, we draw one box filled with that color, and then a
	    // second unfilled one in color (black is none specified)

	    ld.fill = 0;
	    cout << " shaded " << *ld.fillcolor << " ";
	}	

	if ( ld.color ) cout << " outline " << *ld.color << " " ;
	if ( ld.thick ) cout << " thickness " << ld.thick << " " ;
    }

    if ( ld.fill ) cout << " fill " << ld.fill;
    cout << endl;
}

void Picplot::draw(frame *f) {
// Slightly trickier than the circle because we have to output a list
// of strings instead of one.  A functor to convert the DisplayStrings
// to PicDisplayStrings and plot them simplifies matters.
    double x, y;  // To transform the point into device coordinates
    bool in_frame = true;

    // To print a set of strings
    draw_string_f draw_string(f);

    if ( !strs || !loc ) return;

    try {
	x = f->wid * loc->c->map(loc->x,x_axis);
	y = f->ht * loc->c->map(loc->y,y_axis);
    }
    catch (range_error& e) {
	cerr << "Unable to place string at (" << loc->x << ", " << loc->y 
	     << "): " << e.what() << endl;
	return;
    }

    // Clip strings to lie in the graph (if requested)

    if ( x < -EPSILON || x > f->wid + EPSILON ) in_frame = false;
    if ( y < -EPSILON || y > f->ht + EPSILON ) in_frame = false;

    // Make a copy of all the DisplayStrings that are really displayed - either
    // all of them, if the plot is in the graph, or the unclipped ones if the
    // plot is off the graph.
    stringlist v;

    if ( in_frame ) 
	copy(strs->begin(), strs->end(), back_inserter(v));
    else
	remove_copy_if(strs->begin(), strs->end(), back_inserter(v), clipped);

    // If there are strings to show, show them.
    if ( v.size() ) {
	for_each(v.begin(), v.end(), draw_string);

	cout << "at Frame.Origin + (" << x << ", " << y << ")" << endl;
    }
    // Now v will go out of scope and disappear, leaving the object itself
    // alone.
}