-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDlgNetlist.cpp
532 lines (466 loc) · 14.4 KB
/
DlgNetlist.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
// DlgNetlist.cpp : implementation file
//
#include "stdafx.h"
#include "FreePcb.h"
#include "DlgNetlist.h"
#include "DlgEditNet.h"
#include "DlgSetTraceWidths.h"
extern CFreePcbApp theApp;
// columns for list
enum {
COL_VIS = 0,
COL_NAME,
COL_PINS,
COL_WIDTH,
COL_VIA_W,
COL_HOLE_W,
COL_CLEARANCE
};
// sort types
enum {
SORT_UP_NAME = 0,
SORT_DOWN_NAME,
SORT_UP_PINS,
SORT_DOWN_PINS,
SORT_UP_WIDTH,
SORT_DOWN_WIDTH,
SORT_UP_VIA_W,
SORT_DOWN_VIA_W,
SORT_UP_HOLE_W,
SORT_DOWN_HOLE_W,
SORT_UP_CLEARANCE,
SORT_DOWN_CLEARANCE
};
// global so that it is available to Compare() for sorting list control items
static netlist_info nl;
// global callback function for sorting
// lp1, lp2 are indexes to global arrays above
//
int CALLBACK CompareNetlist( LPARAM lp1, LPARAM lp2, LPARAM type )
{
int ret = 0;
switch( type )
{
case SORT_UP_NAME:
case SORT_DOWN_NAME:
ret = (strcmp( ::nl[lp1].name, ::nl[lp2].name ));
break;
case SORT_UP_WIDTH:
case SORT_DOWN_WIDTH:
if( ::nl[lp1].width_attrib.m_seg_width > ::nl[lp2].width_attrib.m_seg_width )
ret = 1;
else if( ::nl[lp1].width_attrib.m_seg_width < ::nl[lp2].width_attrib.m_seg_width )
ret = -1;
break;
case SORT_UP_VIA_W:
case SORT_DOWN_VIA_W:
if( ::nl[lp1].width_attrib.m_via_width > ::nl[lp2].width_attrib.m_via_width )
ret = 1;
else if( ::nl[lp1].width_attrib.m_via_width < ::nl[lp2].width_attrib.m_via_width )
ret = -1;
break;
case SORT_UP_HOLE_W:
case SORT_DOWN_HOLE_W:
if( ::nl[lp1].width_attrib.m_via_hole > ::nl[lp2].width_attrib.m_via_hole )
ret = 1;
else if( ::nl[lp1].width_attrib.m_via_hole < ::nl[lp2].width_attrib.m_via_hole )
ret = -1;
break;
case SORT_UP_PINS:
case SORT_DOWN_PINS:
if( ::nl[lp1].ref_des.GetSize() > ::nl[lp2].ref_des.GetSize() )
ret = 1;
else if( ::nl[lp1].ref_des.GetSize() < ::nl[lp2].ref_des.GetSize() )
ret = -1;
break;
case SORT_UP_CLEARANCE:
case SORT_DOWN_CLEARANCE:
if( ::nl[lp1].width_attrib.m_ca_clearance > ::nl[lp2].width_attrib.m_ca_clearance )
ret = 1;
else if( ::nl[lp1].width_attrib.m_ca_clearance < ::nl[lp2].width_attrib.m_ca_clearance )
ret = -1;
break;
}
switch( type )
{
case SORT_DOWN_NAME:
case SORT_DOWN_WIDTH:
case SORT_DOWN_VIA_W:
case SORT_DOWN_HOLE_W:
case SORT_DOWN_PINS:
case SORT_DOWN_CLEARANCE:
ret = -ret;
break;
}
return ret;
}
// CDlgNetlist dialog
IMPLEMENT_DYNAMIC(CDlgNetlist, CDialog)
CDlgNetlist::CDlgNetlist(CWnd* pParent /*=NULL*/)
: CDialog(CDlgNetlist::IDD, pParent)
{
m_w = 0;
m_v_w = 0;
m_v_h_w = 0;
m_nlist = 0;
}
CDlgNetlist::~CDlgNetlist()
{
}
void CDlgNetlist::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_NET, m_list_ctrl);
DDX_Control(pDX, IDC_BUTTON_VISIBLE, m_button_visible);
DDX_Control(pDX, IDC_BUTTON_EDIT, m_button_edit);
DDX_Control(pDX, IDC_BUTTON_DELETE, m_button_delete);
DDX_Control(pDX, IDC_BUTTON_ADD, m_button_add);
DDX_Control(pDX, IDC_BUTTON_SELECT_ALL, m_button_select_all);
DDX_Control(pDX, IDC_BUTTON_NL_WIDTH, m_button_nl_width);
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, IDCANCEL, m_cancel);
DDX_Control(pDX, IDC_BUTTON_DELETE2, m_button_delete_single);
if( pDX->m_bSaveAndValidate )
{
// update ::nl with visibility data before leaving
int n_local_nets = ::nl.GetSize();
for( int iItem=0; iItem<m_list_ctrl.GetItemCount(); iItem++ )
{
int i = m_list_ctrl.GetItemData( iItem );
::nl[i].visible = ListView_GetCheckState( m_list_ctrl, iItem );
}
}
}
BEGIN_MESSAGE_MAP(CDlgNetlist, CDialog)
// ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST_NET, OnLvnItemchangedListNet)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_NET, OnLvnColumnclickListNet)
ON_BN_CLICKED(IDC_BUTTON_VISIBLE, OnBnClickedButtonVisible)
ON_BN_CLICKED(IDC_BUTTON_EDIT, OnBnClickedButtonEdit)
ON_BN_CLICKED(IDC_BUTTON_SELECT_ALL, OnBnClickedButtonSelectAll)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnBnClickedButtonAdd)
ON_BN_CLICKED(IDC_BUTTON_DELETE, OnBnClickedButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_DELETE2, OnBnClickedButtonDelete)
ON_BN_CLICKED(IDC_BUTTON_NL_WIDTH, OnBnClickedButtonNLWidth)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
ON_BN_CLICKED(IDC_BUTTON_DELETE_NOPINS, OnBnClickedDeleteNetsWithNoPins)
ON_NOTIFY(NM_CLICK, IDC_LIST_NET, OnNMClickListNet)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_NET, &CDlgNetlist::OnNMDblclkListNet)
END_MESSAGE_MAP()
void CDlgNetlist::Initialize( CNetList * nlist, CPartList * plist,
CArray<int> * w, CArray<int> * v_w, CArray<int> * v_h_w )
{
m_nlist = nlist;
m_plist = plist;
m_w = w;
m_v_w = v_w;
m_v_h_w = v_h_w;
}
// CDlgNetlist message handlers
BOOL CDlgNetlist::OnInitDialog()
{
CDialog::OnInitDialog();
// make copy of netlist data so that it can be edited but user can still cancel
// use global netlist_info so it can be sorted in the list control
m_nl = &::nl;
m_nlist->ExportNetListInfo( &::nl );
m_list_ctrl.InsertColumn( COL_VIS, "Vis", LVCFMT_LEFT, 25 );
m_list_ctrl.InsertColumn( COL_NAME, "Name", LVCFMT_LEFT, 140 );
m_list_ctrl.InsertColumn( COL_PINS, "Pins", LVCFMT_LEFT, 40 );
m_list_ctrl.InsertColumn( COL_WIDTH, "Width", LVCFMT_LEFT, 50 );
m_list_ctrl.InsertColumn( COL_VIA_W, "Via W", LVCFMT_LEFT, 53 );
m_list_ctrl.InsertColumn( COL_HOLE_W, "Hole", LVCFMT_LEFT, 53 );
m_list_ctrl.InsertColumn( COL_CLEARANCE, "Clearance", LVCFMT_LEFT, 60 );
// initialize netlist control
m_item_selected = -1;
m_sort_type = 0;
m_visible_state = 1;
DrawListCtrl();
// initialize buttons
m_button_edit.EnableWindow(FALSE);
m_button_delete_single.EnableWindow(FALSE);
m_button_nl_width.EnableWindow(FALSE);
m_button_delete.EnableWindow(FALSE);
return TRUE;
}
// draw listview control and sort according to m_sort_type
//
void CDlgNetlist::DrawListCtrl()
{
int nItem;
CString str;
DWORD old_style = m_list_ctrl.GetExtendedStyle();
m_list_ctrl.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_FLATSB | LVS_EX_CHECKBOXES | old_style );
m_list_ctrl.DeleteAllItems();
int iItem = 0;
for( int i=0; i<::nl.GetSize(); i++ )
{
if( ::nl[i].deleted == FALSE )
{
nItem = m_list_ctrl.InsertItem( iItem, "" );
m_list_ctrl.SetItemData( iItem, (LPARAM)i );
m_list_ctrl.SetItem( iItem, COL_NAME, LVIF_TEXT, ::nl[i].name, 0, 0, 0, 0 );
str.Format( "%d", ::nl[i].ref_des.GetSize() );
m_list_ctrl.SetItem( iItem, COL_PINS, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_seg_width );
m_list_ctrl.SetItem( iItem, COL_WIDTH, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_via_width );
m_list_ctrl.SetItem( iItem, COL_VIA_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_via_hole );
m_list_ctrl.SetItem( iItem, COL_HOLE_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_ca_clearance );
m_list_ctrl.SetItem( iItem, COL_CLEARANCE, LVIF_TEXT, str, 0, 0, 0, 0 );
ListView_SetCheckState( m_list_ctrl, nItem, ::nl[i].visible );
}
}
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
void CDlgNetlist::OnLvnColumnclickListNet(NMHDR *pNMHDR, LRESULT *pResult)
{
LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
int column = pNMLV->iSubItem;
if( column == COL_NAME )
{
if( m_sort_type == SORT_UP_NAME )
m_sort_type = SORT_DOWN_NAME;
else
m_sort_type = SORT_UP_NAME;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
else if( column == COL_WIDTH )
{
if( m_sort_type == SORT_UP_WIDTH )
m_sort_type = SORT_DOWN_WIDTH;
else
m_sort_type = SORT_UP_WIDTH;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
else if( column == COL_VIA_W )
{
if( m_sort_type == SORT_UP_VIA_W )
m_sort_type = SORT_DOWN_VIA_W;
else
m_sort_type = SORT_UP_VIA_W;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
else if( column == COL_HOLE_W )
{
if( m_sort_type == SORT_UP_HOLE_W )
m_sort_type = SORT_DOWN_HOLE_W;
else
m_sort_type = SORT_UP_HOLE_W;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
else if( column == COL_CLEARANCE )
{
if( m_sort_type == SORT_UP_CLEARANCE )
m_sort_type = SORT_DOWN_CLEARANCE;
else
m_sort_type = SORT_UP_CLEARANCE;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
else if( column == COL_PINS )
{
if( m_sort_type == SORT_UP_PINS )
m_sort_type = SORT_DOWN_PINS;
else
m_sort_type = SORT_UP_PINS;
m_list_ctrl.SortItems( ::CompareNetlist, m_sort_type );
}
*pResult = 0;
}
void CDlgNetlist::OnBnClickedButtonVisible()
{
for( int i=0; i<m_list_ctrl.GetItemCount(); i++ )
{
ListView_SetCheckState( m_list_ctrl, i, m_visible_state );
}
for( int i=0; i<::nl.GetSize(); i++ )
{
::nl[i].visible = m_visible_state;
}
m_visible_state = 1 - m_visible_state;
}
void CDlgNetlist::OnBnClickedButtonEdit()
{
int n_sel = m_list_ctrl.GetSelectedCount();
if( n_sel == 0 )
AfxMessageBox( "You have no net selected" );
else if( n_sel > 1 )
AfxMessageBox( "You have more than one net selected" );
else
{
POSITION pos = m_list_ctrl.GetFirstSelectedItemPosition();
if( pos == NULL )
ASSERT(0);
int nItem = m_list_ctrl.GetNextSelectedItem(pos);
int i = m_list_ctrl.GetItemData( nItem );
// prepare and invoke dialog
CFreePcbView * view = theApp.m_View;
CFreePcbDoc * doc = theApp.m_Doc;
CDlgEditNet dlg;
dlg.Initialize( doc->m_nlist, &nl, i, m_plist, FALSE, ListView_GetCheckState( m_list_ctrl, nItem ),
MIL, &(doc->m_w), &(doc->m_v_w), &(doc->m_v_h_w) );
int ret = dlg.DoModal();
if( ret == IDOK )
{
// implement edits into nl and update m_list_ctrl
DrawListCtrl();
}
}
}
void CDlgNetlist::OnBnClickedButtonAdd()
{
// prepare CDlgEditNet
CFreePcbView * view = theApp.m_View;
CFreePcbDoc * doc = theApp.m_Doc;
CDlgEditNet dlg;
dlg.Initialize( doc->m_nlist, &nl, -1, m_plist, TRUE, TRUE,
MIL, &doc->m_w, &doc->m_v_w, &doc->m_v_h_w );
// invoke dialog
int ret = dlg.DoModal();
if( ret == IDOK )
{
// net added, update m_list_ctrl
DrawListCtrl();
}
}
void CDlgNetlist::OnBnClickedOk()
{
OnOK();
}
void CDlgNetlist::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
OnCancel();
}
void CDlgNetlist::OnBnClickedButtonSelectAll()
{
for( int i=0; i<::nl.GetSize(); i++ )
m_list_ctrl.SetItemState( i, LVIS_SELECTED, LVIS_SELECTED );
OnNMClickListNet( NULL, NULL );
}
void CDlgNetlist::OnBnClickedButtonDelete()
{
int n_sel = m_list_ctrl.GetSelectedCount();
if( n_sel == 0 )
{
AfxMessageBox( "You have no net(s) selected" );
}
else
{
// now delete them
while( m_list_ctrl.GetSelectedCount() )
{
POSITION pos = m_list_ctrl.GetFirstSelectedItemPosition();
int i_sel = m_list_ctrl.GetNextSelectedItem( pos );
int i = m_list_ctrl.GetItemData( i_sel );
::nl[i].deleted = TRUE;
m_list_ctrl.DeleteItem( i_sel );
}
}
}
void CDlgNetlist::OnBnClickedButtonNLWidth()
{
CString str;
int n_sel = m_list_ctrl.GetSelectedCount();
if( n_sel == 0 )
{
AfxMessageBox( "You have no net(s) selected" );
return;
}
CFreePcbView * view = theApp.m_View;
CFreePcbDoc * doc = theApp.m_Doc;
CDlgSetTraceWidths dlg;
dlg.m_w = &doc->m_w;
dlg.m_v_w = &doc->m_v_w;
dlg.m_v_h_w = &doc->m_v_h_w;
// Set width attrib in two steps:
// 1) Connection attrib
// 2) Clearance attrib
//
// These two steps don't interfere with each other since they
// set orthogonal parts of m_width_attrib
dlg.m_width_attrib = CConnectionWidthInfo();
dlg.m_width_attrib = CClearanceInfo();
if( n_sel == 1 )
{
POSITION pos = m_list_ctrl.GetFirstSelectedItemPosition();
int iItem = m_list_ctrl.GetNextSelectedItem( pos );
int i = m_list_ctrl.GetItemData( iItem );
dlg.m_width_attrib = ::nl[i].width_attrib;
}
else
{
// Assign the project width attrib (in doc) as the parent
dlg.m_width_attrib.SetParent(doc->m_def_size_attrib);
}
dlg.m_width_attrib.Update();
int ret = dlg.DoModal();
if( ret == IDOK )
{
POSITION pos = m_list_ctrl.GetFirstSelectedItemPosition();
while( pos )
{
int iItem = m_list_ctrl.GetNextSelectedItem( pos );
int i = m_list_ctrl.GetItemData( iItem );
::nl[i].width_attrib = dlg.m_width_attrib;
::nl[i].width_attrib.Update();
::nl[i].apply_trace_width = dlg.m_apply_trace;
::nl[i].apply_via_width = dlg.m_apply_via;
::nl[i].apply_clearance = dlg.m_apply_clearance;
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_seg_width );
m_list_ctrl.SetItem( iItem, COL_WIDTH, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_via_width );
m_list_ctrl.SetItem( iItem, COL_VIA_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_via_hole );
m_list_ctrl.SetItem( iItem, COL_HOLE_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str = CII_FreePcb::GetItemText( ::nl[i].width_attrib.m_ca_clearance );
m_list_ctrl.SetItem( iItem, COL_CLEARANCE, LVIF_TEXT, str, 0, 0, 0, 0 );
}
}
}
void CDlgNetlist::OnBnClickedDeleteNetsWithNoPins()
{
for( int iItem=m_list_ctrl.GetItemCount()-1; iItem>=0; iItem-- )
{
int i_net = m_list_ctrl.GetItemData( iItem );
if( ::nl[i_net].ref_des.GetSize() == 0 )
{
::nl[i_net].deleted = TRUE;
m_list_ctrl.DeleteItem( iItem );
}
}
}
void CDlgNetlist::OnNMClickListNet(NMHDR *pNMHDR, LRESULT *pResult)
{
int n_sel = m_list_ctrl.GetSelectedCount();
if( n_sel == 0 )
{
m_button_edit.EnableWindow(FALSE);
m_button_delete_single.EnableWindow(FALSE);
m_button_nl_width.EnableWindow(FALSE);
m_button_delete.EnableWindow(FALSE);
}
else if( n_sel == 1 )
{
m_button_edit.EnableWindow(TRUE);
m_button_delete_single.EnableWindow(TRUE);
m_button_nl_width.EnableWindow(FALSE);
m_button_delete.EnableWindow(FALSE);
}
else
{
m_button_edit.EnableWindow(FALSE);
m_button_delete_single.EnableWindow(FALSE);
m_button_nl_width.EnableWindow(TRUE);
m_button_delete.EnableWindow(TRUE);
}
if( pResult )
*pResult = 0;
}
void CDlgNetlist::OnNMDblclkListNet(NMHDR *pNMHDR, LRESULT *pResult)
{
OnBnClickedButtonEdit();
*pResult = 0;
}