-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisplayList.cpp
2178 lines (1928 loc) · 63.8 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>
#include "memdc.h"
#include "dle_arc.h"
#include "dle_centroid.h"
#include "dle_circle.h"
#include "dle_donut.h"
#include "dle_hole.h"
#include "dle_line.h"
#include "dle_octagon.h"
#include "dle_oval.h"
#include "dle_rect.h"
#include "dle_rect_rounded.h"
#include "dle_square.h"
#include "dle_x.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
//
dl_element::dl_element()
{
}
// 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++ )
{
// default colors, these should be overwritten with actual colors
m_rgb[layer].Set(
layer*63, // R
(layer/4)*127, // G
(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;
m_vis[layer] = 0;
// Force the creation of "traces" job.
// This is where the traces are added to in the non job specific version of Add()
GetJob_traces(layer);
}
// miscellaneous
m_ratline_w = 1;
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();
// Delete the "traces" jobs
for( int layer=0; layer<MAX_LAYERS; layer++ )
{
delete GetJob_traces(layer);
}
}
// 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->DLinkList_remove();
// destroy element
id el_id = element->id;
delete( element );
return el_id;
}
void CDisplayList::RemoveAllFromLayer( int layer )
{
CDLinkList *pLIST = &m_LIST_job[layer];
for (;;)
{
if( pLIST->next == pLIST ) break;
delete static_cast<CDL_job*>(pLIST->next);
}
// Re-insert the "traces" job
GetJob_traces(layer);
}
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_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
}
void CDisplayList::Scale_pcbu_to_wu(CRect &rect)
{
rect.top /= m_pcbu_per_wu;
rect.bottom /= m_pcbu_per_wu;
rect.left /= m_pcbu_per_wu;
rect.right /= m_pcbu_per_wu;
}
// 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 )
{
// create new element
dl_element * new_element = CreateDLE( id, ptr, layer, gtype, visible,
w, holew, 0,
x,y, xf,yf, xo,yo, radius,
layer );
// Add to traces job in selection layer
CDL_job *pDL_job = GetJob_traces(LAY_SELECTION);
pDL_job->Add(new_element);
return new_element;
}
dl_element * CDisplayList::CreateDLE( int gtype )
{
// create new element and link into list
dl_element * new_element;
switch( gtype )
{
case DL_LINE: new_element = new CDLE_LINE; break;
case DL_CIRC: new_element = new CDLE_CIRC; break;
case DL_DONUT: new_element = new CDLE_DONUT; break;
case DL_SQUARE: new_element = new CDLE_SQUARE; break;
case DL_RECT: new_element = new CDLE_RECT; break;
case DL_RRECT: new_element = new CDLE_RRECT; break;
case DL_OVAL: new_element = new CDLE_OVAL; break;
case DL_OCTAGON: new_element = new CDLE_OCTAGON; break;
case DL_HOLE: new_element = new CDLE_HOLE; break;
case DL_HOLLOW_CIRC: new_element = new CDLE_HOLLOW_CIRC; break;
case DL_HOLLOW_RECT: new_element = new CDLE_HOLLOW_RECT; break;
case DL_HOLLOW_RRECT: new_element = new CDLE_HOLLOW_RRECT; break;
case DL_HOLLOW_OVAL: new_element = new CDLE_HOLLOW_OVAL; break;
case DL_HOLLOW_OCTAGON: new_element = new CDLE_HOLLOW_OCTAGON; break;
case DL_RECT_X: new_element = new CDLE_RECT_X; break;
case DL_ARC_CW: new_element = new CDLE_ARC_CW; break;
case DL_ARC_CCW: new_element = new CDLE_ARC_CCW; break;
case DL_CENTROID: new_element = new CDLE_CENTROID; break;
case DL_X: new_element = new CDLE_X; break;
default: new_element = new dl_element; break;
}
// now copy data from entry into element
new_element->magic = DL_MAGIC;
new_element->dlist = this;
new_element->gtype = gtype;
return new_element;
}
dl_element * CDisplayList::CreateDLE( id id, void * ptr, int layer, int gtype, int visible,
int w, int holew, int clearancew,
int x, int y, int xf, int yf, int xo, int yo, int radius,
int orig_layer )
{
// create new element
dl_element * new_element = CreateDLE( gtype );
if( layer == LAY_RAT_LINE )
{
new_element->w = m_ratline_w;
}
else
{
new_element->w = (w < 0) ? w : w / m_pcbu_per_wu;
}
// now copy data from entry into element
new_element->id = id;
new_element->ptr = ptr;
new_element->visible = visible;
new_element->holew = holew / m_pcbu_per_wu;
new_element->clearancew = clearancew / m_pcbu_per_wu;
new_element->i.x = x / m_pcbu_per_wu;
new_element->i.y = y / m_pcbu_per_wu;
new_element->f.x = xf / m_pcbu_per_wu;
new_element->f.y = yf / m_pcbu_per_wu;
new_element->org.x = xo / m_pcbu_per_wu;
new_element->org.y = 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;
return new_element;
}
dl_element * CDisplayList::MorphDLE( dl_element *pFrom, int to_gtype )
{
// create new element
dl_element * new_element = CreateDLE( to_gtype );
new_element->id = pFrom->id;
new_element->ptr = pFrom->ptr;
new_element->visible = pFrom->visible;
new_element->holew = pFrom->holew;
new_element->clearancew = pFrom->clearancew;
new_element->i = pFrom->i;
new_element->f = pFrom->f;
new_element->org = pFrom->org;
new_element->radius = pFrom->radius;
new_element->sel_vert = pFrom->sel_vert;
new_element->layer = pFrom->layer;
new_element->orig_layer = pFrom->orig_layer;
// Move the element into the same list as pFrom
pFrom->insert_after(new_element);
pFrom->DLinkList_remove();
return new_element;
}
CDL_job_traces * CDisplayList::GetJob_traces( int layer )
{
CDL_job_traces *pJob;
CDLinkList *pElement = m_LIST_job[layer].next;
if( pElement == &m_LIST_job[layer] )
{
pJob = new CDL_job_traces(this);
m_LIST_job[layer].insert_after(pJob);
}
else
{
pJob = static_cast< CDL_job_traces * >(pElement);
}
return pJob;
}
void CDisplayList::Add( CDL_job *pDL_job, int layer )
{
m_LIST_job[layer].move_before(pDL_job);
}
// Add entry to end of list, returns pointer to element created.
//
// Entry is added to the given job.
//
// Dimensional units for input parameters are PCBU
//
dl_element * CDisplayList::Add( CDL_job *pDL_job, id id, void * ptr, int layer, int gtype, int visible,
int w, int holew, int clearancew, int x, int y, int xf, int yf, int xo, int yo,
int radius )
{
// create new element
dl_element * new_element = CreateDLE( id, ptr, layer, gtype, visible,
w, holew, clearancew,
x,y, xf,yf, xo,yo, radius,
layer );
// Link into job
pDL_job->Add(new_element);
return new_element;
}
// Add entry to end of list, returns pointer to element created.
//
// Entry is added to the traces job. If that job doesn't exist, it will be 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 clearancew,
int x, int y, int xf, int yf, int xo, int yo,
int radius, int orig_layer )
{
// create new element
dl_element * new_element = CreateDLE( id, ptr, layer, gtype, visible,
w, holew, clearancew,
x,y, xf,yf, xo,yo, radius,
orig_layer );
// Link into traces job
CDL_job *pDL_job = GetJob_traces(layer);
pDL_job->Add(new_element);
return new_element;
}
void CDisplayList::Add( dl_element * element )
{
// Link into traces job
CDL_job *pDL_job = GetJob_traces(element->layer);
pDL_job->Add(element);
}
// set element parameters in PCBU
//
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_clearance( dl_element * el, int clearance )
{
if( el)
el->clearancew = clearance/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->org.x = x_org/m_pcbu_per_wu;
}
void CDisplayList::Set_y_org( dl_element * el, int y_org )
{
if( el)
el->org.y = y_org/m_pcbu_per_wu;
}
void CDisplayList::Set_x( dl_element * el, int x )
{
if( el)
el->i.x = x/m_pcbu_per_wu;
}
void CDisplayList::Set_y( dl_element * el, int y )
{
if( el)
el->i.y = y/m_pcbu_per_wu;
}
void CDisplayList::Set_xf( dl_element * el, int xf )
{
if( el)
el->f.x = xf/m_pcbu_per_wu;
}
void CDisplayList::Set_yf( dl_element * el, int yf )
{
if( el)
el->f.y = 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->i.x += dx;
el->i.y += dy;
el->org.x += dx;
el->org.y += dy;
el->f.x += dx;
el->f.y += 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->org.x*m_pcbu_per_wu; }
int CDisplayList::Get_y_org( dl_element * el ) { return el->org.y*m_pcbu_per_wu; }
int CDisplayList::Get_x( dl_element * el ) { return el->i.x*m_pcbu_per_wu; }
int CDisplayList::Get_y( dl_element * el ) { return el->i.y*m_pcbu_per_wu; }
int CDisplayList::Get_xf( dl_element * el ) { return el->f.x*m_pcbu_per_wu; }
int CDisplayList::Get_yf( dl_element * el ) { return el->f.y*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;
}
// 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( C_RGB::black );
// create pens and brushes
CPen black_pen ( PS_SOLID, 1, C_RGB::white );
CPen white_pen ( PS_SOLID, 1, C_RGB::black );
CPen grid_pen ( PS_SOLID, 1, m_rgb[LAY_VISIBLE_GRID] );
CPen backgnd_pen( PS_SOLID, 1, m_rgb[LAY_BACKGND] );
CPen board_pen ( PS_SOLID, 1, m_rgb[LAY_BOARD_OUTLINE] );
CBrush black_brush( C_RGB::black );
CBrush backgnd_brush( m_rgb[LAY_BACKGND] );
CBrush * old_brush;
CPen * old_pen;
// 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 );
// visual grid
if( m_visual_grid_on && (m_visual_grid_spacing/m_scale)>5 && m_vis[LAY_VISIBLE_GRID] )
{
int startix = m_org_x/m_visual_grid_spacing;
int startiy = m_org_y/m_visual_grid_spacing;
double start_grid_x = startix*m_visual_grid_spacing;
double start_grid_y = startiy*m_visual_grid_spacing;
for( double ix=start_grid_x; ix<m_max_x; ix+=m_visual_grid_spacing )
{
for( double iy=start_grid_y; iy<m_max_y; iy+=m_visual_grid_spacing )
{
pDC->SetPixel( ix, iy, m_rgb[LAY_VISIBLE_GRID] );
}
}
}
// now traverse the lists, starting with the layer in the last element
// of the m_order[] array
CDrawInfo di;
di.DC_Master = pDC;
CMemDC dcMemory(pDC);
for( int order=(MAX_LAYERS-1); order>=0; order-- )
{
int layer = m_layer_in_order[order];
if( !m_vis[layer] || layer == LAY_SELECTION )
{
continue;
}
if( layer > LAY_BOARD_OUTLINE )
{
// Use transparent DC in dcMemory
di.DC = &dcMemory;
dcMemory.mono();
di.layer_color[0] = C_RGB::mono_off;
di.layer_color[1] = C_RGB::mono_on;
}
else
{
// Draw directly on main DC (di.DC_Master) for speed
di.DC = di.DC_Master;
di.layer_color[0] = m_rgb[LAY_BACKGND];
di.layer_color[1] = m_rgb[layer];
}
// Run drawing jobs for this layer
CDLinkList *pElement;
for( pElement = m_LIST_job[layer].next; pElement != &m_LIST_job[layer]; pElement = pElement->next )
{
CDL_job *pJob = static_cast<CDL_job*>(pElement);
pJob->Draw(di);
}
if( di.DC != di.DC_Master )
{
// di.DC is a monochrome mask
// DC_Master &= ~mask
// 0 = transparent (AND with ~RGB(0,0,0) -> no effect, D AND 1 = D)
// 1 = solid (AND with ~RGB(255,255,255) -> clear the masked area to RGB(0,0,0)
di.DC_Master->SetTextColor(RGB(0,0,0));
di.DC_Master->SetBkColor(RGB(255,255,255));
di.DC_Master->BitBlt(m_org_x, m_org_y, m_max_x-m_org_x, m_max_y-m_org_y,
di.DC,
m_org_x, m_org_y, 0x00220326);
// DC_Master |= mask
// 0 = transparent (OR with RBG(0,0,0) -> no effect D OR 0 = D)
// 1 = solid (OR the masked area with layer color -> 0 OR C = C)
di.DC_Master->SetBkColor( m_rgb[layer] );
di.DC_Master->BitBlt(m_org_x, m_org_y, m_max_x-m_org_x, m_max_y-m_org_y,
di.DC,
m_org_x, m_org_y, SRCPAINT);
}
}
dcMemory.DeleteDC();
// 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, m_rgb[m_drag_layer] );
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, m_rgb[m_drag_layer] );
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, m_rgb[m_drag_layer_0] );
CPen * old_pen = pDC->SelectObject( &pen0 );
pDC->LineTo( m_drag_xi, m_drag_yi );
// draw second segment
CPen pen1( PS_SOLID, m_drag_w1, m_rgb[m_drag_layer_1] );
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, m_rgb[m_drag_layer_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, m_rgb[m_drag_layer_1] );
// 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
ASSERT(0);
if( m_drag_shape == DS_LINE_VERTEX )
{
CPen pen( PS_SOLID, m_drag_w2, m_rgb[m_drag_layer_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
ASSERT(0);
pDC->SelectObject( old_pen );
}
pDC->SelectObject( old_pen );
// see if leading via needs to be drawn
if( m_drag_via_drawn )
{
// draw or undraw via
int thick = (m_drag_via_w - m_drag_via_holew)/2;
int w = m_drag_via_w - thick;
int holew = m_drag_via_holew;
// CPen pen( PS_SOLID, thick, m_rgb[LAY_PAD_THRU] );
CPen pen( PS_SOLID, thick, m_rgb[m_drag_layer_1] );
CPen * old_pen = pDC->SelectObject( &pen );
CBrush black_brush( C_RGB::black );
CBrush * old_brush = pDC->SelectObject( &black_brush );
pDC->Ellipse( m_drag_xi - w/2, m_drag_yi - w/2, m_drag_xi + w/2, m_drag_yi + w/2 );
pDC->SelectObject( old_brush );
pDC->SelectObject( old_pen );
}
}
else if( m_drag_shape == DS_ARC_STRAIGHT || m_drag_shape == DS_ARC_CW || m_drag_shape == DS_ARC_CCW )
{
CPen pen_w( PS_SOLID, m_drag_w1, m_rgb[m_drag_layer_1] );
// redraw dragged shape
pDC->SelectObject( &pen_w );
if( m_drag_shape == DS_ARC_STRAIGHT )
DrawArc( pDC, DL_LINE, m_drag_x, m_drag_y, m_drag_xi, m_drag_yi );
else if( m_drag_shape == DS_ARC_CW )
DrawArc( pDC, DL_ARC_CW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
else if( m_drag_shape == DS_ARC_CCW )
DrawArc( pDC, DL_ARC_CCW, m_drag_xi, m_drag_yi, m_drag_x, m_drag_y );
pDC->SelectObject( old_pen );
m_last_drag_shape = m_drag_shape;
}
}
// if cross hairs, draw them
if( m_cross_hairs )
{
// draw cross-hairs
COLORREF bk = pDC->SetBkColor( C_RGB::black );
CPen pen( PS_DOT, 0, C_RGB::grey );
pDC->SelectObject( &pen );
int x = m_cross_bottom.x;
int y = m_cross_left.y;
m_cross_left.x = m_org_x;
m_cross_right.x = m_max_x;
m_cross_bottom.y = m_org_y;
m_cross_top.y = m_max_y;
if( x-m_org_x > y-m_org_y )
{
// bottom-left cursor line intersects m_org_y
m_cross_botleft.x = x - (y - m_org_y);
m_cross_botleft.y = m_org_y;
}
else
{
// bottom-left cursor line intersects m_org_x
m_cross_botleft.x = m_org_x;
m_cross_botleft.y = y - (x - m_org_x);
}
if( m_max_x-x > y-m_org_y )
{
// bottom-right cursor line intersects m_org_y
m_cross_botright.x = x + (y - m_org_y);
m_cross_botright.y = m_org_y;
}
else
{
// bottom-right cursor line intersects m_max_x
m_cross_botright.x = m_max_x;
m_cross_botright.y = y - (m_max_x - x);
}
if( x-m_org_x > m_max_y-y )
{
// top-left cursor line intersects m_max_y
m_cross_topleft.x = x - (m_max_y - y);
m_cross_topleft.y = m_max_y;
}
else
{
// top-left cursor line intersects m_org_x
m_cross_topleft.x = m_org_x;
m_cross_topleft.y = y + (x - m_org_x);
}
if( m_max_x-x > m_max_y-y )
{
// top-right cursor line intersects m_max_y
m_cross_topright.x = x + (m_max_y - y);
m_cross_topright.y = m_max_y;
}
else
{
// top-right cursor line intersects m_max_x
m_cross_topright.x = m_max_x;
m_cross_topright.y = y + (m_max_x - x);
}
pDC->MoveTo( m_cross_left );
pDC->LineTo( m_cross_right );
pDC->MoveTo( m_cross_bottom );
pDC->LineTo( m_cross_top );
if( m_cross_hairs == 2 )
{
pDC->MoveTo( m_cross_topleft );
pDC->LineTo( m_cross_botright );
pDC->MoveTo( m_cross_botleft );
pDC->LineTo( m_cross_topright );
}
pDC->SelectObject( old_pen );
pDC->SetBkColor( bk );
}
pDC->SetROP2( old_ROP2 );
// restore original objects
pDC->SelectObject( old_pen );
pDC->SelectObject( old_brush );
// double-buffer to screen
if( memDC )
{
dDC->BitBlt( m_org_x, m_org_y, m_max_x-m_org_x, m_max_y-m_org_y, pDC, m_org_x, m_org_y, SRCCOPY );
}
}
// set the display color for a layer
//
void CDisplayList::SetLayerRGB( int layer, C_RGB color )
{
m_rgb[layer] = color;
}
void CDisplayList::SetLayerVisible( int layer, BOOL vis )
{
m_vis[layer] = vis;
}
// test x,y for a hit on an item in the selection layer
// creates arrays with layer and id of each hit item
// assigns priority based on layer and id
// then returns pointer to item with highest priority
// If exclude_id != NULL, excludes item with
// id == exclude_id and ptr == exclude_ptr
// If include_id != NULL, only include items that match include_id[]
// where n_include_ids is size of array, and
// where 0's in include_id[] fields are treated as wildcards
//
// Returns: Index into hit_info[] if hit, -1 if no hit
int CDisplayList::TestSelect(
int x, int y,
CDL_job::HitInfo hit_info[], int max_hits, int &num_hits,
id * exclude_id, void * exclude_ptr,
id * include_id, int n_include_ids )
{
int best_hit = -1;
// Get the traces job (last in job list)
if( m_vis[LAY_SELECTION] )
{
CDL_job_traces *pJob = GetJob_traces(LAY_SELECTION);
CPoint point(x/m_pcbu_per_wu, y/m_pcbu_per_wu);
num_hits = pJob->TestForHit(point, hit_info, max_hits-1);
// now return highest priority hit
if( num_hits == 0 )
{
goto no_hit;
}
else
{
// Mark the end of the hit array with invalid layer.
// assign priority to each hit, track maximum, exclude exclude_id item
int best_hit_priority = 0;
for( int i=0; i<num_hits; i++ )
{
BOOL excluded_hit = FALSE;
BOOL included_hit = TRUE;
if( exclude_id )
{
if( hit_info[i].ID == *exclude_id && hit_info[i].ptr == exclude_ptr )
excluded_hit = TRUE;
}
if( include_id )
{
included_hit = FALSE;
for( int inc=0; inc<n_include_ids; inc++ )
{
id * inc_id = &include_id[inc];
if( inc_id->type == hit_info[i].ID.type
&& ( inc_id->st == 0 || inc_id->st == hit_info[i].ID.st )
&& ( inc_id->i == 0 || inc_id->i == hit_info[i].ID.i )
&& ( inc_id->sst == 0 || inc_id->sst == hit_info[i].ID.sst )
&& ( inc_id->ii == 0 || inc_id->ii == hit_info[i].ID.ii ) )
{
included_hit = TRUE;
break;
}
}
}
if( !excluded_hit && included_hit )
{
// OK, valid hit, now assign priority
// start with reversed layer drawing order * 10
// i.e. last drawn = highest priority
int priority = (MAX_LAYERS - m_order_for_layer[hit_info[i].layer])*10;
// bump priority for small items which may be overlapped by larger items on same layer
if( hit_info[i].ID.type == ID_PART && hit_info[i].ID.st == ID_SEL_REF_TXT )
priority++;
else if( hit_info[i].ID.type == ID_PART && hit_info[i].ID.st == ID_SEL_VALUE_TXT )