-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathDisplayList.cpp
2607 lines (2422 loc) · 79.3 KB
/
DisplayList.cpp
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
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// DisplayList.cpp : implementation of class CDisplayList
//
// this is a linked-list of display elements
// each element is a primitive graphics object such as a line-segment,
// circle, annulus, etc.
//
#include "stdafx.h"
#include <math.h>
// dimensions passed to DisplayList from the application are in PCBU (i.e. nm)
// since the Win95/98 GDI uses 16-bit arithmetic, PCBU must be scaled to DU (i.e. mils)
//
//#define PCBU_PER_DU PCBU_PER_WU
//#define MIL_PER_DU NM_PER_MIL/PCBU_PER_DU // conversion from mils to display units
//#define DU_PER_MIL PCBU_PER_DU/NM_PER_MIL // conversion from display units to mils
#define DL_MAX_LAYERS 32
#define HILITE_POINT_W 10 // size/2 of selection box for points (mils)
// constructor
//
CDisplayList::CDisplayList( int pcbu_per_wu )
{
m_pcbu_per_wu = pcbu_per_wu;
// create lists for all layers
for( int layer=0; layer<MAX_LAYERS; layer++ )
{
// linked list for layer
m_start[layer].prev = 0; // first element
m_start[layer].next = &m_end[layer];
m_start[layer].magic = 0;
m_end[layer].next = 0; // last element
m_end[layer].prev = &m_start[layer];
m_end[layer].magic = 0;
// default colors, these should be overwritten with actual colors
m_rgb[layer][0] = layer*63; // R
m_rgb[layer][1] = (layer/4)*127; // G
m_rgb[layer][2] = (layer/8)*63; // B
// default order
m_layer_in_order[layer] = layer; // will be drawn from highest to lowest
m_order_for_layer[layer] = layer;
}
// miscellaneous
m_drag_flag = 0;
m_drag_num_lines = 0;
m_drag_line_pt = 0;
m_drag_num_ratlines = 0;
m_drag_ratline_start_pt = 0;
m_drag_ratline_end_pt = 0;
m_drag_ratline_width = 0;
m_cross_hairs = 0;
m_visual_grid_on = 0;
m_visual_grid_spacing = 0;
m_inflection_mode = IM_NONE;
}
// destructor
//
CDisplayList::~CDisplayList()
{
RemoveAll();
}
void CDisplayList::RemoveAllFromLayer( int layer )
{
// traverse list for layer, removing all elements
while( m_end[layer].prev != &m_start[layer] )
Remove( m_end[layer].prev );
}
void CDisplayList::RemoveAll()
{
// traverse lists for all layers, removing all elements
for( int layer=0; layer<MAX_LAYERS; layer++ )
{
RemoveAllFromLayer( layer );
}
if( m_drag_line_pt )
{
free( m_drag_line_pt );
m_drag_line_pt = 0;
}
if( m_drag_ratline_start_pt )
{
free( m_drag_ratline_start_pt );
m_drag_ratline_start_pt = 0;
}
if( m_drag_ratline_end_pt )
{
free( m_drag_ratline_end_pt );
m_drag_ratline_end_pt = 0;
}
}
// Set conversion parameters between world coords (used by elements in
// display list) and window coords (pixels)
//
// enter with:
// client_r = window client rectangle (pixels)
// screen_r = window client rectangle in screen coords (pixels)
// pane_org_x = starting x-coord of PCB drawing area in client rect (pixels)
// pane_org_y = starting y-coord of PCB drawing area in client rect (pixels)
// pane_bottom_h = height of bottom pane (pixels)
// pcb units per pixel = nm per pixel
// org_x = x-coord of left edge of drawing area (pcb units)
// org_y = y-coord of bottom edge of drawing area (pcb units)
//
// note that the actual scale factor is set by the arguments to
// SetWindowExt and SetViewportExt, and may be slightly different for x and y
//
void CDisplayList::SetMapping( CRect *client_r, CRect *screen_r, int pane_org_x, int pane_bottom_h,
double pcbu_per_pixel, int org_x, int org_y )
{
m_client_r = client_r; // pixels
m_screen_r = screen_r; // pixels
m_pane_org_x = pane_org_x; // pixels
m_bottom_pane_h = pane_bottom_h; // pixels
m_pane_org_y = client_r->bottom - pane_bottom_h; // pixels
m_scale = pcbu_per_pixel/m_pcbu_per_wu; // world units per pixel
m_org_x = org_x/m_pcbu_per_wu; // world units
m_org_y = org_y/m_pcbu_per_wu; // world units
//now set extents
double rw = m_client_r.Width(); // width of client area (pixels)
double rh = m_client_r.Height(); // height of client area (pixels)
double ext_x = rw*pcbu_per_pixel/m_pcbu_per_wu; // width in WU
double ext_y = rh*pcbu_per_pixel/m_pcbu_per_wu; // height in WU
int div = 1, mult = 1;
if( m_pcbu_per_wu >=25400 )
{
// this is necessary for Win95/98 (16-bit GDI)
int ext_max = max( ext_x, ext_y );
if( ext_max > 30000 )
div = ext_max/15000;
}
else
mult = m_pcbu_per_wu;
if( ext_x*mult/div > INT_MAX )
ASSERT(0);
if( ext_y*mult/div > INT_MAX )
ASSERT(0);
w_ext_x = ext_x*mult/div;
v_ext_x = rw*mult/div;
w_ext_y = ext_y*mult/div;
v_ext_y = -rh*mult/div;
m_wu_per_pixel_x = (double)w_ext_x/v_ext_x; // actual ratios
m_wu_per_pixel_y = (double)w_ext_y/v_ext_y;
m_pcbu_per_pixel_x = m_wu_per_pixel_x * m_pcbu_per_wu;
m_pcbu_per_pixel_y = m_wu_per_pixel_y * m_pcbu_per_wu;
m_max_x = m_org_x + m_wu_per_pixel_x*(client_r->right-pane_org_x) + 2; // world units
m_max_y = m_org_y - m_wu_per_pixel_y*client_r->bottom + 2; // world units
}
// add graphics element used for selection
//
dl_element * CDisplayList::AddSelector( id id, void * ptr, int layer, int gtype, int visible,
int w, int holew, int x, int y, int xf, int yf, int xo, int yo,
int radius )
{
dl_element * test = Add( id, ptr, LAY_SELECTION, gtype, visible,
w, holew, x, y, xf, yf, xo, yo, radius, layer );
test->layer = layer;
return test;
}
// Add entry to end of list, returns pointer to element created.
//
// Dimensional units for input parameters are PCBU
//
dl_element * CDisplayList::Add( id id, void * ptr, int layer, int gtype, int visible,
int w, int holew, int x, int y, int xf, int yf, int xo, int yo,
int radius, int orig_layer )
{
// create new element and link into list
dl_element * new_element = new dl_element;
new_element->prev = m_end[layer].prev;
new_element->next = &m_end[layer];
new_element->prev->next = new_element;
new_element->next->prev = new_element;
// now copy data from entry into element
new_element->magic = DL_MAGIC;
new_element->id = id;
new_element->ptr = ptr;
new_element->gtype = gtype;
new_element->visible = visible;
new_element->w = w/m_pcbu_per_wu;
new_element->holew = holew/m_pcbu_per_wu;
new_element->x = x/m_pcbu_per_wu;
new_element->xf = xf/m_pcbu_per_wu;
new_element->y = y/m_pcbu_per_wu;
new_element->yf = yf/m_pcbu_per_wu;
new_element->x_org = xo/m_pcbu_per_wu;
new_element->y_org = yo/m_pcbu_per_wu;
new_element->radius = radius/m_pcbu_per_wu;
new_element->sel_vert = 0;
new_element->layer = layer;
new_element->orig_layer = orig_layer;
new_element->dlist = this;
return new_element;
}
// set element parameters in PCBU
//
void CDisplayList::Set_gtype( dl_element * el, int gtype )
{
if( el)
el->gtype = gtype;
}
void CDisplayList::Set_visible( dl_element * el, int visible )
{
if( el)
el->visible = visible;
}
void CDisplayList::Set_sel_vert( dl_element * el, int sel_vert )
{
if( el)
el->sel_vert = sel_vert;
}
void CDisplayList::Set_w( dl_element * el, int w )
{
if( el)
el->w = w/m_pcbu_per_wu;
}
void CDisplayList::Set_holew( dl_element * el, int holew )
{
if( el)
el->holew = holew/m_pcbu_per_wu;
}
void CDisplayList::Set_x_org( dl_element * el, int x_org )
{
if( el)
el->x_org = x_org/m_pcbu_per_wu;
}
void CDisplayList::Set_y_org( dl_element * el, int y_org )
{
if( el)
el->y_org = y_org/m_pcbu_per_wu;
}
void CDisplayList::Set_x( dl_element * el, int x )
{
if( el)
el->x = x/m_pcbu_per_wu;
}
void CDisplayList::Set_y( dl_element * el, int y )
{
if( el)
el->y = y/m_pcbu_per_wu;
}
void CDisplayList::Set_xf( dl_element * el, int xf )
{
if( el)
el->xf = xf/m_pcbu_per_wu;
}
void CDisplayList::Set_yf( dl_element * el, int yf )
{
if( el)
el->yf = yf/m_pcbu_per_wu;
}
void CDisplayList::Set_layer( dl_element * el, int layer )
{
if( el)
el->layer = layer;
}
void CDisplayList::Set_radius( dl_element * el, int radius )
{
if( el)
el->radius = radius/m_pcbu_per_wu;
}
void CDisplayList::Set_id( dl_element * el, id * id )
{
if( el)
el->id = *id;
}
void CDisplayList::Move( dl_element * el, int dx, int dy )
{
el->x += dx;
el->y += dy;
el->x_org += dx;
el->y_org += dy;
el->xf += dx;
el->yf += dy;
}
// get element parameters in PCBU
//
void * CDisplayList::Get_ptr( dl_element * el ) { return el->ptr; }
int CDisplayList::Get_gtype( dl_element * el ) { return el->gtype; }
int CDisplayList::Get_visible( dl_element * el ) { return el->visible; }
int CDisplayList::Get_sel_vert( dl_element * el ) { return el->sel_vert; }
int CDisplayList::Get_w( dl_element * el ) { return el->w*m_pcbu_per_wu; }
int CDisplayList::Get_holew( dl_element * el ) { return el->holew*m_pcbu_per_wu; }
int CDisplayList::Get_x_org( dl_element * el ) { return el->x_org*m_pcbu_per_wu; }
int CDisplayList::Get_y_org( dl_element * el ) { return el->y_org*m_pcbu_per_wu; }
int CDisplayList::Get_x( dl_element * el ) { return el->x*m_pcbu_per_wu; }
int CDisplayList::Get_y( dl_element * el ) { return el->y*m_pcbu_per_wu; }
int CDisplayList::Get_xf( dl_element * el ) { return el->xf*m_pcbu_per_wu; }
int CDisplayList::Get_yf( dl_element * el ) { return el->yf*m_pcbu_per_wu; }
int CDisplayList::Get_radius( dl_element * el ) { return el->radius*m_pcbu_per_wu; }
int CDisplayList::Get_layer( dl_element * el ) { return el->layer; }
id CDisplayList::Get_id( dl_element * el ) { return el->id; }
void CDisplayList::Get_Endpoints(CPoint *cpi, CPoint *cpf)
{
cpi->x = m_drag_xi*m_pcbu_per_wu; cpi->y = m_drag_yi*m_pcbu_per_wu;
cpf->x = m_drag_xf*m_pcbu_per_wu; cpf->y = m_drag_yf*m_pcbu_per_wu;
}
// Remove element from list, return id
//
id CDisplayList::Remove( dl_element * element )
{
if( !element )
{
id no_id;
return no_id;
}
if( element->magic != DL_MAGIC )
{
ASSERT(0);
id no_id;
return no_id;
}
// remove links to this element
element->next->prev = element->prev;
element->prev->next = element->next;
// destroy element
id el_id = element->id;
delete( element );
return el_id;
}
// Draw the display list using device DC or memory DC
//
void CDisplayList::Draw( CDC * dDC )
{
CDC * pDC;
if( memDC )
pDC = memDC;
else
pDC = dDC;
pDC->SetBkColor( RGB(0, 0, 0) );
// create pens and brushes
CPen * old_pen;
CPen black_pen( PS_SOLID, 1, RGB( 0, 0, 0 ) );
CPen white_pen( PS_SOLID, 1, RGB( 255, 255, 255 ) );
CPen grid_pen( PS_SOLID, 1,
RGB( m_rgb[LAY_VISIBLE_GRID][0],
m_rgb[LAY_VISIBLE_GRID][1],
m_rgb[LAY_VISIBLE_GRID][2] ) );
CPen backgnd_pen( PS_SOLID, 1,
RGB( m_rgb[LAY_BACKGND][0],
m_rgb[LAY_BACKGND][1],
m_rgb[LAY_BACKGND][2] ) );
CPen board_pen( PS_SOLID, 1,
RGB( m_rgb[LAY_BOARD_OUTLINE][0],
m_rgb[LAY_BOARD_OUTLINE][1],
m_rgb[LAY_BOARD_OUTLINE][2] ) );
CBrush * old_brush;
CBrush black_brush( RGB( 0, 0, 0 ) );
CBrush backgnd_brush( RGB( m_rgb[LAY_BACKGND][0],
m_rgb[LAY_BACKGND][1],
m_rgb[LAY_BACKGND][2] ) );
// paint it background color
old_brush = pDC->SelectObject( &backgnd_brush );
old_pen = pDC->SelectObject( &black_pen );
CRect client_rect;
client_rect.left = m_org_x;
client_rect.right = m_max_x;
client_rect.bottom = m_org_y;
client_rect.top = m_max_y;
pDC->Rectangle( &client_rect );
DrawVisualGrid(pDC);
// now traverse the lists, starting with the layer in the last element
// of the m_order[] array
int nlines = 0;
int size_of_2_pixels = 2*m_scale;
for( int order=(MAX_LAYERS-1); order>=0; order-- )
{
int layer = m_layer_in_order[order];
if( !m_vis[layer] || layer == LAY_SELECTION )
continue;
CPen line_pen( PS_SOLID, 1, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
CBrush fill_brush( RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &line_pen );
pDC->SelectObject( &fill_brush );
dl_element * el = &m_start[layer];
while( el->next->next )
{
el = el->next;
if( el->visible && m_vis[el->orig_layer] )
{
int xi = el->x;
int xf = el->xf;
int yi = el->y;
int yf = el->yf;
int w = el->w;
if( el->gtype == DL_CIRC || el->gtype == DL_HOLLOW_CIRC )
{
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
if( el->gtype == DL_HOLLOW_CIRC )
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->Ellipse( xi - w/2, yi - w/2, xi + w/2, yi + w/2 );
if( el->gtype == DL_HOLLOW_CIRC )
pDC->SelectObject( fill_brush );
}
}
if( el->gtype == DL_HOLE )
{
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
if( w>size_of_2_pixels )
pDC->Ellipse( xi - w/2, yi - w/2, xi + w/2, yi + w/2 );
}
}
else if( el->gtype == DL_CENTROID )
{
// x,y are center coords; w = width;
// xf,yf define arrow end-point for P&P orientation
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->Ellipse( xi - w/4, yi - w/4, xi + w/4, yi + w/4 );
pDC->SelectObject( fill_brush );
xi = el->x - el->w/2;
xf = el->x + el->w/2;
yi = el->y - el->w/2;
yf = el->y + el->w/2;
pDC->MoveTo( xi, yi );
pDC->LineTo( xf, yf );
pDC->MoveTo( xf, yi );
pDC->LineTo( xi, yf );
pDC->MoveTo( el->x, el->y ); // p&p arrow
pDC->LineTo( el->xf, el->yf ); //
if( el->y == el->yf )
{
// horizontal arrow
pDC->LineTo( el->xf - (el->xf - el->x)/4,
el->yf + w/4 );
pDC->LineTo( el->xf - (el->xf - el->x)/4,
el->yf - w/4 );
pDC->LineTo( el->xf, el->yf );
}
else if( el->x == el->xf )
{
// vertical arrow
pDC->LineTo( el->xf + w/4, el->yf - (el->yf - el->y)/4 );
pDC->LineTo( el->xf - w/4, el->yf - (el->yf - el->y)/4 );
pDC->LineTo( el->xf, el->yf );
}
else
ASSERT(0);
int w_pp = el->w/10;
nlines += 2;
}
}
else if( el->gtype == DL_DONUT )
{
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
int thick = (w - el->holew)/2;
int ww = w - thick;
int holew = el->holew;
int size_of_2_pixels = m_scale;
if( thick < size_of_2_pixels )
{
holew = w - 2*size_of_2_pixels;
if( holew < 0 )
holew = 0;
thick = (w - holew)/2;
ww = w - thick;
}
if( w-el->holew > 0 )
{
CPen pen( PS_SOLID, thick, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
pDC->SelectObject( &backgnd_brush );
pDC->Ellipse( xi - ww/2, yi - ww/2, xi + ww/2, yi + ww/2 );
pDC->SelectObject( line_pen );
pDC->SelectObject( fill_brush );
}
else
{
CPen backgnd_pen( PS_SOLID, 1,
RGB( m_rgb[LAY_BACKGND][0],
m_rgb[LAY_BACKGND][1],
m_rgb[LAY_BACKGND][2] ) );
pDC->SelectObject( &backgnd_pen );
pDC->SelectObject( &backgnd_brush );
pDC->Ellipse( xi - holew/2, yi - holew/2, xi + holew/2, yi + holew/2 );
pDC->SelectObject( line_pen );
pDC->SelectObject( fill_brush );
}
}
}
else if( el->gtype == DL_SQUARE )
{
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
int holew = el->holew;
pDC->Rectangle( xi - w/2, yi - w/2, xi + w/2, yi + w/2 );
if( holew )
{
pDC->SelectObject( &backgnd_brush );
pDC->SelectObject( &backgnd_pen );
pDC->Ellipse( xi - holew/2, yi - holew/2,
xi + holew/2, yi + holew/2 );
pDC->SelectObject( fill_brush );
pDC->SelectObject( line_pen );
}
}
}
else if( el->gtype == DL_OCTAGON || el->gtype == DL_HOLLOW_OCTAGON )
{
if( xi-w/2 < m_max_x && xi+w/2 > m_org_x
&& yi-w/2 < m_max_y && yi+w/2 > m_org_y )
{
const double pi = 3.14159265359;
POINT pt[8];
double angle = pi/8.0;
for( int iv=0; iv<8; iv++ )
{
pt[iv].x = el->x + 0.5 * el->w * cos(angle);
pt[iv].y = el->y + 0.5 * el->w * sin(angle);
angle += pi/4.0;
}
int holew = el->holew;
if( el->gtype == DL_HOLLOW_OCTAGON )
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->Polygon( pt, 8 );
if( el->gtype == DL_HOLLOW_OCTAGON )
pDC->SelectObject( fill_brush );
if( holew )
{
pDC->SelectObject( &backgnd_brush );
pDC->SelectObject( &backgnd_pen );
pDC->Ellipse( xi - holew/2, yi - holew/2,
xi + holew/2, yi + holew/2 );
pDC->SelectObject( fill_brush );
pDC->SelectObject( line_pen );
}
}
}
else if( el->gtype == DL_RECT )
{
if( xf < xi )
{
xf = xi;
xi = el->xf;
}
if( yf < yi )
{
yf = yi;
yi = el->yf;
}
if( xi < m_max_x && xf > m_org_x && yi < m_max_y && yf > m_org_y )
{
int holew = el->holew;
pDC->Rectangle( xi, yi, xf, yf );
if( holew )
{
pDC->SelectObject( &black_brush );
pDC->SelectObject( &black_pen );
pDC->Ellipse( el->x_org - holew/2, el->y_org - holew/2,
el->x_org + holew/2, el->y_org + holew/2 );
pDC->SelectObject( fill_brush );
pDC->SelectObject( line_pen );
}
}
}
else if( el->gtype == DL_HOLLOW_RECT )
{
if( xf < xi )
{
xf = xi;
xi = el->xf;
}
if( yf < yi )
{
yf = yi;
yi = el->yf;
}
if( xi < m_max_x && xf > m_org_x
&& yi < m_max_y && yf > m_org_y )
{
pDC->MoveTo( xi, yi );
pDC->LineTo( xf, yi );
pDC->LineTo( xf, yf );
pDC->LineTo( xi, yf );
pDC->LineTo( xi, yi );
nlines += 4;
}
}
else if( el->gtype == DL_OVAL || el->gtype == DL_HOLLOW_OVAL )
{
if( xf < xi )
{
xf = xi;
xi = el->xf;
}
if( yf < yi )
{
yf = yi;
yi = el->yf;
}
if( xi < m_max_x && xf > m_org_x && yi < m_max_y && yf > m_org_y )
{
int h = abs(xf-xi);
int v = abs(yf-yi);
int r = min(h,v);
if( el->gtype == DL_HOLLOW_OVAL )
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->RoundRect( xi, yi, xf, yf, r, r );
if( el->gtype == DL_HOLLOW_OVAL )
pDC->SelectObject( fill_brush );
int holew = el->holew;
if( el->holew )
{
pDC->SelectObject( &black_brush );
pDC->SelectObject( &black_pen );
pDC->Ellipse( el->x_org - holew/2, el->y_org - holew/2,
el->x_org + holew/2, el->y_org + holew/2 );
pDC->SelectObject( fill_brush );
pDC->SelectObject( line_pen );
}
}
}
else if( el->gtype == DL_RRECT || el->gtype == DL_HOLLOW_RRECT )
{
if( xf < xi )
{
xf = xi;
xi = el->xf;
}
if( yf < yi )
{
yf = yi;
yi = el->yf;
}
if( xi < m_max_x && xf > m_org_x && yi < m_max_y && yf > m_org_y )
{
int holew = el->holew;
if( el->gtype == DL_HOLLOW_RRECT )
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->RoundRect( xi, yi, xf, yf, 2*el->radius, 2*el->radius );
if( el->gtype == DL_HOLLOW_RRECT )
pDC->SelectObject( fill_brush );
if( holew )
{
pDC->SelectObject( &black_brush );
pDC->SelectObject( &black_pen );
pDC->Ellipse( el->x_org - holew/2, el->y_org - holew/2,
el->x_org + holew/2, el->y_org + holew/2 );
pDC->SelectObject( fill_brush );
pDC->SelectObject( line_pen );
}
}
}
else if( el->gtype == DL_RECT_X )
{
if( xf < xi )
{
xf = xi;
xi = el->xf;
}
if( yf < yi )
{
yf = yi;
yi = el->yf;
}
if( xi < m_max_x && xf > m_org_x
&& yi < m_max_y && yf > m_org_y )
{
pDC->MoveTo( el->x, el->y );
pDC->LineTo( el->xf, el->y );
pDC->LineTo( el->xf, el->yf );
pDC->LineTo( el->x, el->yf );
pDC->LineTo( el->x, el->y );
pDC->MoveTo( el->x, el->y );
pDC->LineTo( el->xf, el->yf );
pDC->MoveTo( el->x, el->yf );
pDC->LineTo( el->xf, el->y );
nlines += 4;
}
}
else if( el->gtype == DL_ARC_CW )
{
if( ( (el->xf >= el->x && el->x < m_max_x && el->xf > m_org_x)
|| (el->xf < el->x && el->xf < m_max_x && el->x > m_org_x) )
&& ( (el->yf >= el->y && el->y < m_max_y && el->yf > m_org_y)
|| (el->yf < el->y && el->yf < m_max_y && el->y > m_org_y) ) )
{
CPen pen( PS_SOLID, el->w, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
DrawArc( pDC, DL_ARC_CW, el->x, el->y, el->xf, el->yf );
pDC->SelectObject( line_pen );
}
}
else if( el->gtype == DL_ARC_CCW )
{
if( ( (el->xf >= el->x && el->x < m_max_x && el->xf > m_org_x)
|| (el->xf < el->x && el->xf < m_max_x && el->x > m_org_x) )
&& ( (el->yf >= el->y && el->y < m_max_y && el->yf > m_org_y)
|| (el->yf < el->y && el->yf < m_max_y && el->y > m_org_y) ) )
{
CPen pen( PS_SOLID, el->w, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
DrawArc( pDC, DL_ARC_CCW, el->x, el->y, el->xf, el->yf );
pDC->SelectObject( line_pen );
}
}
else if( el->gtype == DL_CURVE_CW )
{
if( ( (el->xf >= el->x && el->x < m_max_x && el->xf > m_org_x)
|| (el->xf < el->x && el->xf < m_max_x && el->x > m_org_x) )
&& ( (el->yf >= el->y && el->y < m_max_y && el->yf > m_org_y)
|| (el->yf < el->y && el->yf < m_max_y && el->y > m_org_y) ) )
{
CPen pen( PS_SOLID, el->w, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
DrawCurve( pDC, DL_CURVE_CW, el->x, el->y, el->xf, el->yf );
pDC->SelectObject( line_pen );
}
}
else if( el->gtype == DL_CURVE_CCW )
{
if( ( (el->xf >= el->x && el->x < m_max_x && el->xf > m_org_x)
|| (el->xf < el->x && el->xf < m_max_x && el->x > m_org_x) )
&& ( (el->yf >= el->y && el->y < m_max_y && el->yf > m_org_y)
|| (el->yf < el->y && el->yf < m_max_y && el->y > m_org_y) ) )
{
CPen pen( PS_SOLID, el->w, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
DrawCurve( pDC, DL_CURVE_CCW, el->x, el->y, el->xf, el->yf );
pDC->SelectObject( line_pen );
}
}
else if( el->gtype == DL_X )
{
xi = el->x - el->w/2;
xf = el->x + el->w/2;
yi = el->y - el->w/2;
yf = el->y + el->w/2;
if( xi < m_max_x && xf > m_org_x
&& yi < m_max_y && yf > m_org_y )
{
pDC->MoveTo( xi, yi );
pDC->LineTo( xf, yf );
pDC->MoveTo( xf, yi );
pDC->LineTo( xi, yf );
nlines += 2;
}
}
else if( el->gtype == DL_LINE )
{
// only draw line segments which are in viewport
// viewport bounds, enlarged to account for line thickness
int Yb = m_org_y - w/2; // y-coord of viewport top
int Yt = m_max_y + w/2; // y-coord of bottom
int Xl = m_org_x - w/2; // x-coord of left edge
int Xr = m_max_x - w/2; // x-coord of right edge
// line segment from (xi,yi) to (xf,yf)
int draw_flag = 0;
// now test for all conditions where drawing is necessary
if( xi==xf )
{
// vertical line
if( yi<yf )
{
// upward
if( yi<=Yt && yf>=Yb && xi<=Xr && xi>=Xl )
draw_flag = 1;
}
else
{
// downward
if( yf<=Yt && yi>=Yb && xi<=Xr && xi>=Xl )
draw_flag = 1;
}
}
else if( yi==yf )
{
// horizontal line
if( xi<xf )
{
// rightward
if( xi<=Xr && xf>=Xl && yi<=Yt && yi>=Yb )
draw_flag = 1;
}
else
{
// leftward
if( xf<=Xr && xi>=Xl && yi<=Yt && yi>=Yb )
draw_flag = 1;
}
}
else if( !((xi<Xl&&xf<Xl)||(xi>Xr&&xf>Xr)||(yi<Yb&&yf<Yb)||(yi>Yt&&yf>Yt)) )
{
// oblique line
// not entirely above or below or right or left of viewport
// get slope b and intercept a so that y=a+bx
double b = (double)(yf-yi)/(xf-xi);
int a = yi - int(b*xi);
// now test for line in viewport
if( abs((yf-yi)*(Xr-Xl)) > abs((xf-xi)*(Yt-Yb)) )
{
// line is more vertical than window diagonal
int x1 = int((Yb-a)/b);
if( x1>=Xl && x1<=Xr)
draw_flag = 1; // intercepts bottom of screen
else
{
int x2 = int((Yt-a)/b);
if( x2>=Xl && x2<=Xr )
draw_flag = 1; // intercepts top of screen
}
}
else
{
// line is more horizontal than window diagonal
int y1 = int(a + b*Xl);
if( y1>=Yb && y1<=Yt )
draw_flag = 1; // intercepts left edge of screen
else
{
int y2 = a + int(b*Xr);
if( y2>=Yb && y2<=Yt )
draw_flag = 1; // intercepts right edge of screen
}
}
}
// now draw the line segment if not clipped
if( draw_flag )
{
CPen pen( PS_SOLID, w, RGB( m_rgb[layer][0], m_rgb[layer][1], m_rgb[layer][2] ) );
pDC->SelectObject( &pen );
pDC->MoveTo( xi, yi );
pDC->LineTo( xf, yf );
pDC->SelectObject( line_pen );
nlines++;
}
}
}
}
// restore original objects
pDC->SelectObject( old_pen );
pDC->SelectObject( old_brush );
}
// origin
CRect r;
r.top = 25*NM_PER_MIL/m_pcbu_per_wu;
r.left = -25*NM_PER_MIL/m_pcbu_per_wu;
r.right = 25*NM_PER_MIL/m_pcbu_per_wu;
r.bottom = -25*NM_PER_MIL/m_pcbu_per_wu;
pDC->SelectObject( &grid_pen );
pDC->SelectObject( GetStockObject( HOLLOW_BRUSH ) );
pDC->MoveTo( -100*NM_PER_MIL/m_pcbu_per_wu, 0 );
pDC->LineTo( -25*NM_PER_MIL/m_pcbu_per_wu, 0 );
pDC->MoveTo( 100*NM_PER_MIL/m_pcbu_per_wu, 0 );
pDC->LineTo( 25*NM_PER_MIL/m_pcbu_per_wu, 0 );
pDC->MoveTo( 0, -100*NM_PER_MIL/m_pcbu_per_wu );
pDC->LineTo( 0, -25*NM_PER_MIL/m_pcbu_per_wu );
pDC->MoveTo( 0, 100*NM_PER_MIL/m_pcbu_per_wu );
pDC->LineTo( 0, 25*NM_PER_MIL/m_pcbu_per_wu );
pDC->Ellipse( r );
pDC->SelectObject( old_pen );
pDC->SelectObject( old_brush );
// if dragging, draw drag lines or shape
int old_ROP2 = pDC->GetROP2();
pDC->SetROP2( R2_XORPEN );
if( m_drag_num_lines )
{
// draw line array
CPen drag_pen( PS_SOLID, 1, RGB( m_rgb[m_drag_layer][0],
m_rgb[m_drag_layer][1], m_rgb[m_drag_layer][2] ) );
CPen * old_pen = pDC->SelectObject( &drag_pen );
for( int il=0; il<m_drag_num_lines; il++ )
{
pDC->MoveTo( m_drag_x+m_drag_line_pt[2*il].x, m_drag_y+m_drag_line_pt[2*il].y );
pDC->LineTo( m_drag_x+m_drag_line_pt[2*il+1].x, m_drag_y+m_drag_line_pt[2*il+1].y );
}
pDC->SelectObject( old_pen );
}
if( m_drag_num_ratlines )
{
// draw ratline array
CPen drag_pen( PS_SOLID, m_drag_ratline_width, RGB( m_rgb[m_drag_layer][0],
m_rgb[m_drag_layer][1], m_rgb[m_drag_layer][2] ) );
CPen * old_pen = pDC->SelectObject( &drag_pen );
for( int il=0; il<m_drag_num_ratlines; il++ )
{
pDC->MoveTo( m_drag_ratline_start_pt[il].x, m_drag_ratline_start_pt[il].y );
pDC->LineTo( m_drag_x+m_drag_ratline_end_pt[il].x, m_drag_y+m_drag_ratline_end_pt[il].y );
}
pDC->SelectObject( old_pen );
}
if( m_drag_flag )
{
// 4. Redraw the three segments:
if(m_drag_shape == DS_SEGMENT)
{
pDC->MoveTo( m_drag_xb, m_drag_yb );
// draw first segment
CPen pen0( PS_SOLID, m_drag_w0, RGB( m_rgb[m_drag_layer_0][0],
m_rgb[m_drag_layer_0][1], m_rgb[m_drag_layer_0][2] ) );
CPen * old_pen = pDC->SelectObject( &pen0 );
pDC->LineTo( m_drag_xi, m_drag_yi );
// draw second segment
CPen pen1( PS_SOLID, m_drag_w1, RGB( m_rgb[m_drag_layer_1][0],
m_rgb[m_drag_layer_1][1], m_rgb[m_drag_layer_1][2] ) );
pDC->SelectObject( &pen1 );
pDC->LineTo( m_drag_xf, m_drag_yf );
// draw third segment
if(m_drag_style2 != DSS_NONE)
{
CPen pen2( PS_SOLID, m_drag_w2, RGB( m_rgb[m_drag_layer_2][0],
m_rgb[m_drag_layer_2][1], m_rgb[m_drag_layer_2][2] ) );
pDC->SelectObject( &pen2 );
pDC->LineTo( m_drag_xe, m_drag_ye );
}
pDC->SelectObject( old_pen );
}
// draw drag shape, if used
if( m_drag_shape == DS_LINE_VERTEX || m_drag_shape == DS_LINE )
{
CPen pen_w( PS_SOLID, m_drag_w1, RGB( m_rgb[m_drag_layer_1][0],
m_rgb[m_drag_layer_1][1], m_rgb[m_drag_layer_1][2] ) );
// draw dragged shape
pDC->SelectObject( &pen_w );
if( m_drag_style1 == DSS_STRAIGHT )
{
if( m_inflection_mode == IM_NONE )
{
pDC->MoveTo( m_drag_xi, m_drag_yi );
pDC->LineTo( m_drag_x, m_drag_y );
}
else
{
CPoint pi( m_drag_xi, m_drag_yi );
CPoint pf( m_drag_x, m_drag_y );
CPoint p = GetInflectionPoint( pi, pf, m_inflection_mode );
pDC->MoveTo( m_drag_xi, m_drag_yi );
if( p != pi )
pDC->LineTo( p.x, p.y );
pDC->LineTo( m_drag_x, m_drag_y );
}
m_last_inflection_mode = m_inflection_mode;
}
else if( m_drag_style1 == DSS_ARC_CW )
DrawArc( pDC, DL_ARC_CW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
else if( m_drag_style1 == DSS_ARC_CCW )
DrawArc( pDC, DL_ARC_CCW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
else if( m_drag_style1 == DSS_CURVE_CW )
DrawCurve( pDC, DL_CURVE_CW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
else if( m_drag_style1 == DSS_CURVE_CCW )
DrawCurve( pDC, DL_CURVE_CCW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
else
ASSERT(0);
if( m_drag_shape == DS_LINE_VERTEX )
{
CPen pen( PS_SOLID, m_drag_w2, RGB( m_rgb[m_drag_layer_2][0],
m_rgb[m_drag_layer_2][1], m_rgb[m_drag_layer_2][2] ) );
pDC->SelectObject( &pen );
if( m_drag_style2 == DSS_STRAIGHT )
pDC->LineTo( m_drag_xf, m_drag_yf );
else if( m_drag_style2 == DSS_ARC_CW )
DrawArc( pDC, DL_ARC_CW, m_drag_x, m_drag_y, m_drag_xf, m_drag_yf );
else if( m_drag_style2 == DSS_ARC_CCW )
DrawArc( pDC, DL_ARC_CCW, m_drag_x, m_drag_y, m_drag_xf, m_drag_yf );
else if( m_drag_style2 == DSS_CURVE_CW )
DrawCurve( pDC, DL_CURVE_CW, m_drag_x, m_drag_y, m_drag_xf, m_drag_yf );
else if( m_drag_style2 == DSS_CURVE_CCW )
DrawCurve( pDC, DL_CURVE_CCW, m_drag_x, m_drag_y, m_drag_xf, m_drag_yf );
else
ASSERT(0);
pDC->SelectObject( old_pen );