-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDesignRules.cpp
514 lines (485 loc) · 14.7 KB
/
DesignRules.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
// Implementation of class DRErrorList
//
#include "stdafx.h"
//******************************************************
//
// class DRError
//
// constructor
//
DRError::DRError()
{
dl_el = NULL;
dl_sel = NULL;
}
DRError::~DRError()
{
if( dl_el )
{
dl_el->Remove();
dl_sel->Remove();
}
}
//******************************************************
//
// class DRErrorList
//
// constructor
//
DRErrorList::DRErrorList()
{
m_dlist = NULL;
}
DRErrorList::~DRErrorList()
{
Clear();
}
// Set the DisplayList for error symbols
//
void DRErrorList::SetLists( CPartList * pl, CNetList * nl, CDisplayList * dl )
{
m_plist = pl;
m_nlist = nl;
m_dlist = dl;
}
// clear all entries from DRE list
//
void DRErrorList::Clear()
{
while( !list.IsEmpty() )
{
void * ptr = list.GetHead();
DRError * dre = (DRError*)ptr;
delete dre;
list.RemoveHead();
}
}
// Remove entry from list
//
void DRErrorList::Remove( DRError * dre )
{
POSITION pos = list.Find( dre );
if( pos )
{
list.RemoveAt( pos );
delete dre;
}
}
// Add error to list
//
DRError * DRErrorList::Add( long index, int type, CString * str,
CString * name1, CString * name2, id id1, id id2,
int x1, int y1, int x2, int y2, int w, int layer )
{
#define DRE_MIN_SIZE 50*NM_PER_MIL
POSITION pos;
void * ptr;
// find center of coords
int x = x1;
int y = y1;
if( name2 )
{
x = (x1 + x2)/2;
y = (y1 + y2)/2;
}
// first check for redundant error
if( !list.IsEmpty() )
{
for( pos = list.GetHeadPosition(); pos != NULL; )
{
ptr = list.GetNext( pos );
DRError * dre = (DRError*)ptr;
// compare current error with error from list
// if identical id's, don't add it
if( dre->id1 == id1 && dre->id2 == id2 )
return NULL;
if( dre->id1 == id2 && dre->id2 == id1 )
return NULL;
// if same traces at same point, don't add it
if( name2 )
{
if( id1.type == ID_NET && id1.st == ID_CONNECT
&& dre->id1.type == ID_NET && dre->id1.st == ID_CONNECT
&& id1.i == dre->id1.i
&& id2.type == ID_NET && id2.st == ID_CONNECT
&& dre->id2.type == ID_NET && dre->id2.st == ID_CONNECT
&& id2.i == dre->id2.i
&& x == dre->x && y == dre->y )
return NULL;
if( id2.type == ID_NET && id2.st == ID_CONNECT
&& dre->id1.type == ID_NET && dre->id1.st == ID_CONNECT
&& id2.i == dre->id1.i
&& id1.type == ID_NET && id1.st == ID_CONNECT
&& dre->id2.type == ID_NET && dre->id2.st == ID_CONNECT
&& id1.i == dre->id2.i
&& x == dre->x && y == dre->y )
return NULL;
}
// if RING_PAD error on same pad, don't add it
if( type == DRError::RING_PAD && dre->m_id.sst == DRError::RING_PAD )
{
if( *name1 == dre->name1
&& id1.i == dre->id1.i )
{
// same pad, ignore it
return NULL;
}
}
// if BOARDEDGE_PAD or BOARDEDGE_PADHOLE error on same pad, don't add it
if( (type == DRError::BOARDEDGE_PAD || type == DRError::BOARDEDGE_PADHOLE)
&& (dre->m_id.sst == DRError::BOARDEDGE_PAD || dre->m_id.sst == DRError::BOARDEDGE_PADHOLE) )
{
if( *name1 == dre->name1
&& id1.i == dre->id1.i )
{
// same pad, ignore it
return NULL;
}
}
// if RING_VIA error on same via, don't add it
if( type == DRError::RING_VIA && dre->m_id.sst == DRError::RING_VIA )
{
if( *name1 == dre->name1
&& id1.i == dre->id1.i
&& id1.ii == dre->id1.ii )
{
// same via, ignore it
return NULL;
}
}
// if BOARDEDGE_VIA or BOARDEDGE_VIAHOLE error on same via, don't add it
if( (type == DRError::BOARDEDGE_VIA || type == DRError::BOARDEDGE_VIAHOLE)
&& (dre->m_id.sst == DRError::BOARDEDGE_VIA || dre->m_id.sst == DRError::BOARDEDGE_VIAHOLE) )
{
if( *name1 == dre->name1
&& id1.i == dre->id1.i
&& id1.ii == dre->id1.ii )
{
// same via, ignore it
return NULL;
}
}
// if BOARDEDGE_TRACE on same trace at same point, don't add it
if( type == DRError::BOARDEDGE_TRACE && dre->m_id.sst == DRError::BOARDEDGE_TRACE )
{
if( *name1 == dre->name1
&& x == dre->x
&& y == dre->y )
{
return NULL;
}
}
// if BOARDEDGE_COPPERAREA on same area at same point, don't add it
if( type == DRError::BOARDEDGE_COPPERAREA
&& dre->m_id.sst == DRError::BOARDEDGE_COPPERAREA )
{
if( *name1 == dre->name1
&& id1.i == dre->id1.i
&& x == dre->x
&& y == dre->y )
{
return NULL;
}
}
if( type == DRError::COPPERAREA_COPPERAREA
&& dre->m_id.sst == DRError::COPPERAREA_COPPERAREA )
{
if( *name1 == dre->name1
&& *name2 == dre->name2
&& id1.i == dre->id1.i
&& id2.i == dre->id2.i
&& x == dre->x
&& y == dre->y )
return NULL;
}
}
}
DRError * dre = new DRError;
// make id
dre->m_id.type = ID_DRC;
dre->m_id.st = ID_DRE;
dre->m_id.i = (unsigned int)dre;
dre->m_id.sst = type;
dre->m_id.ii = index;
// set rest of params
dre->name1 = *name1;
if( name2 )
dre->name2 = *name2;
dre->str = *str;
dre->id1 = id1;
if( name2 )
dre->id2 = id2;
dre->x = x;
dre->y = y;
dre->layer = layer;
if( m_dlist )
{
int d = DRE_MIN_SIZE/2;
if( name2 )
d = max( DRE_MIN_SIZE, Distance( x1, y1, x2, y2 ) )/2;
if( w )
d = max( d, w/2 );
int ww = 2*d;
dre->dl_el = m_dlist->Add( dre->m_id, (void*)dre, LAY_DRC_ERROR,
DL_HOLLOW_CIRC, 1, ww, 0, 0, x, y, 0, 0, x, y );
dre->m_id.st = ID_SEL_DRE;
dre->dl_sel = m_dlist->AddSelector( dre->m_id, (void*)dre, LAY_DRC_ERROR,
DL_HOLLOW_CIRC, 1, ww, 0, x, y, 0, 0, x, y );
}
list.AddTail( dre );
return dre;
}
// returns the graphic element for pad
// if none, returns the element for the pad's hole
//
dl_element * GetPadElement( part_pin * pin, int layer )
{
dl_element * el = NULL;
int il = layer - LAY_TOP_COPPER;
if( layer > 0 && pin->dl_els.GetSize() > il )
el = pin->dl_els[il];
if( el == NULL )
el = pin->dl_hole;
return el;
}
// Highlight the error in the layout window
//
void DRErrorList::HighLight( DRError * dre )
{
m_dlist->Add( dre->m_id, dre, LAY_HILITE, dre->dl_el->gtype, 1,
m_dlist->Get_w( dre->dl_el ),
m_dlist->Get_holew( dre->dl_el ),
0, // no clearance needed
m_dlist->Get_x( dre->dl_el ),
m_dlist->Get_y( dre->dl_el ),
m_dlist->Get_xf( dre->dl_el ),
m_dlist->Get_yf( dre->dl_el ),
m_dlist->Get_x_org( dre->dl_el ),
m_dlist->Get_y_org( dre->dl_el ) );
dl_element * dl1 = NULL;
dl_element * dl2 = NULL;
if( dre->m_id.sst == DRError::PAD_PAD
|| dre->m_id.sst == DRError::PAD_PADHOLE
|| dre->m_id.sst == DRError::PADHOLE_PADHOLE
)
{
// add highlights for pads
cpart * part1 = m_plist->GetPart( dre->name1 );
if( part1 && dre->id1.i < part1->pin.GetSize() )
// dl1 = part1->pin[dre->id1.i].dl_el;
dl1 = GetPadElement( &part1->pin[dre->id1.i], dre->layer );
cpart * part2 = m_plist->GetPart( dre->name2 );
if( part2 && dre->id2.i < part2->pin.GetSize() )
// dl2 = part2->pin[dre->id2.i].dl_el;
dl2 = GetPadElement( &part2->pin[dre->id2.i], dre->layer );
}
else if( dre->m_id.sst == DRError::SEG_PAD
|| dre->m_id.sst == DRError::SEG_PADHOLE
)
{
// add highlights for trace and pad
cnet * net = m_nlist->GetNetPtrByName( &dre->name1 );
if( net && dre->id1.i < net->nconnects && dre->id1.ii < net->connect[dre->id1.i].nsegs )
dl1 = net->connect[dre->id1.i].seg[dre->id1.ii].dl_el;
cpart * part = m_plist->GetPart( dre->name2 );
if( part && dre->id2.i < part->pin.GetSize() )
dl2 = GetPadElement( &part->pin[dre->id2.i], dre->layer );
}
else if( dre->m_id.sst == DRError::VIA_PAD
|| dre->m_id.sst == DRError::VIA_PADHOLE
|| dre->m_id.sst == DRError::VIAHOLE_PAD
|| dre->m_id.sst == DRError::VIAHOLE_PADHOLE
)
{
// add highlights for via and pad
cnet * net = m_nlist->GetNetPtrByName( &dre->name1 );
if( net && dre->id1.i < net->nconnects && dre->id1.ii <= net->connect[dre->id1.i].nsegs )
dl1 = net->connect[dre->id1.i].vtx[dre->id1.ii].dl_el[0];
cpart * part = m_plist->GetPart( dre->name2 );
if( part && dre->id2.i < part->pin.GetSize() )
dl2 = GetPadElement( &part->pin[dre->id2.i], dre->layer );
}
else if( dre->m_id.sst == DRError::SEG_SEG )
{
// add highlights for traces
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nconnects && dre->id1.ii < net1->connect[dre->id1.i].nsegs )
dl1 = net1->connect[dre->id1.i].seg[dre->id1.ii].dl_el;
cnet * net2 = m_nlist->GetNetPtrByName( &dre->name2 );
if( net2 && dre->id1.i < net2->nconnects && dre->id2.ii < net2->connect[dre->id2.i].nsegs )
dl2 = net2->connect[dre->id2.i].seg[dre->id2.ii].dl_el;
}
else if( dre->m_id.sst == DRError::SEG_VIA
|| dre->m_id.sst == DRError::SEG_VIAHOLE
)
{
// add highlights for trace and via
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nconnects && dre->id1.ii < net1->connect[dre->id1.i].nsegs )
dl1 = net1->connect[dre->id1.i].seg[dre->id1.ii].dl_el;
cnet * net2 = m_nlist->GetNetPtrByName( &dre->name2 );
if( net2 && dre->id2.i < net2->nconnects && dre->id2.ii <= net2->connect[dre->id2.i].nsegs )
dl2 = net2->connect[dre->id2.i].vtx[dre->id2.ii].dl_el[0];
}
else if( dre->m_id.sst == DRError::VIA_VIA
|| dre->m_id.sst == DRError::VIA_VIAHOLE
|| dre->m_id.sst == DRError::VIAHOLE_VIAHOLE
)
{
// add highlights for vias
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nconnects && dre->id1.ii <= net1->connect[dre->id1.i].nsegs )
dl1 = net1->connect[dre->id1.i].vtx[dre->id1.ii].dl_el[0];
cnet * net2 = m_nlist->GetNetPtrByName( &dre->name2 );
if( net2 && dre->id1.i < net2->nconnects && dre->id2.ii <= net2->connect[dre->id2.i].nsegs )
dl2 = net2->connect[dre->id2.i].vtx[dre->id2.ii].dl_el[0];
}
else if( dre->m_id.sst == DRError::TRACE_WIDTH
|| dre->m_id.sst == DRError::BOARDEDGE_TRACE )
{
// add highlight for trace segment
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nconnects && dre->id1.ii < net1->connect[dre->id1.i].nsegs )
dl1 = net1->connect[dre->id1.i].seg[dre->id1.ii].dl_el;
}
else if( dre->m_id.sst == DRError::RING_PAD
|| dre->m_id.sst == DRError::BOARDEDGE_PAD
|| dre->m_id.sst == DRError::BOARDEDGE_PADHOLE )
{
// add highlight for pad
cpart * part = m_plist->GetPart( dre->name1 );
if( part && dre->id1.i < part->pin.GetSize() )
dl1 = GetPadElement( &part->pin[dre->id1.i], dre->layer );
}
else if( dre->m_id.sst == DRError::RING_VIA
|| dre->m_id.sst == DRError::BOARDEDGE_VIA
|| dre->m_id.sst == DRError::BOARDEDGE_VIAHOLE )
{
// add highlight for via
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nconnects && dre->id1.ii <= net1->connect[dre->id1.i].nsegs )
dl1 = net1->connect[dre->id1.i].vtx[dre->id1.ii].dl_el[0];
}
else if( dre->m_id.sst == DRError::BOARDEDGE_COPPERAREA )
{
// add highlight for copper area side
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nareas )
net1->area[dre->id1.i].poly->HighlightSide(dre->id1.ii);
}
else if( dre->m_id.sst == DRError::COPPERAREA_COPPERAREA )
{
// add highlights for copper area sides
cnet * net1 = m_nlist->GetNetPtrByName( &dre->name1 );
if( net1 && dre->id1.i < net1->nareas )
net1->area[dre->id1.i].poly->HighlightSide(dre->id1.ii);
cnet * net2 = m_nlist->GetNetPtrByName( &dre->name2 );
if( net2 && dre->id2.i < net2->nareas )
net2->area[dre->id2.i].poly->HighlightSide(dre->id2.ii);
}
else if( dre->m_id.sst == DRError::COPPERAREA_INSIDE_COPPERAREA )
{
}
else if( dre->m_id.sst == DRError::UNROUTED )
{
// add highlights for pad
cpart * part1 = m_plist->GetPart( dre->name1 );
if( part1 && dre->id1.i < part1->pin.GetSize() )
dl1 = GetPadElement( &part1->pin[dre->id1.i], dre->layer );
cpart * part2 = m_plist->GetPart( dre->name2 );
if( part2 && dre->id2.i < part2->pin.GetSize() )
dl2 = GetPadElement( &part2->pin[dre->id2.i], dre->layer );
}
else
ASSERT(0);
if( dl1 )
{
m_dlist->Add( dre->m_id, dre, LAY_HILITE, dl1->gtype, 1,
m_dlist->Get_w( dl1 ),
m_dlist->Get_holew( dl1 ),
0, // no clearance needed
m_dlist->Get_x( dl1 ),
m_dlist->Get_y( dl1 ),
m_dlist->Get_xf( dl1 ),
m_dlist->Get_yf( dl1 ),
m_dlist->Get_x_org( dl1 ),
m_dlist->Get_y_org( dl1 ),
m_dlist->Get_radius( dl1 ) );
}
if( dl2 )
{
m_dlist->Add( dre->m_id, dre, LAY_HILITE, dl2->gtype, 1,
m_dlist->Get_w( dl2 ),
m_dlist->Get_holew( dl2 ),
0, // no clearance needed
m_dlist->Get_x( dl2 ),
m_dlist->Get_y( dl2 ),
m_dlist->Get_xf( dl2 ),
m_dlist->Get_yf( dl2 ),
m_dlist->Get_x_org( dl2 ),
m_dlist->Get_y_org( dl2 ),
m_dlist->Get_radius( dl2 ) );
}
}
// Make symbol for the error a solid circle with diameter = 250 mils
//
void DRErrorList::MakeSolidCircles()
{
POSITION pos;
void * ptr;
if( !list.IsEmpty() )
{
for( pos = list.GetHeadPosition(); pos != NULL; )
{
ptr = list.GetNext( pos );
DRError * dre = (DRError*)ptr;
if( dre->dl_el )
{
if( dre->dl_el->gtype == DL_HOLLOW_CIRC )
{
dl_element *old_element = dre->dl_el;
dl_element *old_sel = dre->dl_sel;
dre->dl_el = m_dlist->MorphDLE(old_element, DL_CIRC);
m_dlist->Set_holew( dre->dl_el, m_dlist->Get_w( old_element ) );
m_dlist->Set_w ( dre->dl_el, 250*NM_PER_MIL );
dre->dl_sel = m_dlist->MorphDLE(old_sel, DL_CIRC);
m_dlist->Set_holew( dre->dl_sel, m_dlist->Get_w( old_sel ) );
m_dlist->Set_w ( dre->dl_sel, 250*NM_PER_MIL );
old_element->Remove();
old_sel->Remove();
}
}
}
}
}
// Make symbol for error a ring
//
void DRErrorList::MakeHollowCircles()
{
POSITION pos;
void * ptr;
if( !list.IsEmpty() )
{
for( pos = list.GetHeadPosition(); pos != NULL; )
{
ptr = list.GetNext( pos );
DRError * dre = (DRError*)ptr;
if( dre->dl_el )
{
if( dre->dl_el->gtype == DL_CIRC )
{
dl_element *old_element = dre->dl_el;
dl_element *old_sel = dre->dl_sel;
dre->dl_el = m_dlist->MorphDLE(old_element, DL_HOLLOW_CIRC);
m_dlist->Set_w ( dre->dl_el, m_dlist->Get_holew( old_element ) );
m_dlist->Set_holew( dre->dl_el, 0 );
dre->dl_sel = m_dlist->MorphDLE(old_sel, DL_HOLLOW_CIRC);
m_dlist->Set_w ( dre->dl_sel, m_dlist->Get_holew( old_sel ) );
m_dlist->Set_holew( dre->dl_sel, 0 );
old_element->Remove();
old_sel->Remove();
}
}
}
}
}