forked from jpt13653903/FreePCB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgNetCombine.cpp
276 lines (246 loc) · 6.78 KB
/
DlgNetCombine.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
// DlgNetlist.cpp : implementation file
//
#include "stdafx.h"
#include "FreePcb.h"
#include "DlgNetlist.h"
#include "DlgEditNet.h"
#include "DlgSetTraceWidths.h"
#include "DlgNetCombine.h"
#include "DlgChooseNetName.h"
extern CFreePcbApp theApp;
// columns for list
enum {
COL_NAME = 0,
COL_PINS,
COL_WIDTH,
COL_VIA_W,
COL_HOLE_W
};
// 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
};
// global so that it is available to Compare() for sorting list control items
netlist_info nl_combine;
// global callback function for sorting
// lp1, lp2 are indexes to global arrays above
//
int CALLBACK CompareNetlistCombine( LPARAM lp1, LPARAM lp2, LPARAM type )
{
int ret = 0;
switch( type )
{
case SORT_UP_NAME:
case SORT_DOWN_NAME:
ret = (strcmp( ::nl_combine[lp1].name, ::nl_combine[lp2].name ));
break;
case SORT_UP_WIDTH:
case SORT_DOWN_WIDTH:
if( ::nl_combine[lp1].w > ::nl_combine[lp2].w )
ret = 1;
else if( ::nl_combine[lp1].w < ::nl_combine[lp2].w )
ret = -1;
break;
case SORT_UP_VIA_W:
case SORT_DOWN_VIA_W:
if( ::nl_combine[lp1].v_w > ::nl_combine[lp2].v_w )
ret = 1;
else if( ::nl_combine[lp1].v_w < ::nl_combine[lp2].v_w )
ret = -1;
break;
case SORT_UP_HOLE_W:
case SORT_DOWN_HOLE_W:
if( ::nl_combine[lp1].v_h_w > ::nl_combine[lp2].v_h_w )
ret = 1;
else if( ::nl_combine[lp1].v_h_w < ::nl_combine[lp2].v_h_w )
ret = -1;
break;
case SORT_UP_PINS:
case SORT_DOWN_PINS:
if( ::nl_combine[lp1].ref_des.GetSize() > ::nl_combine[lp2].ref_des.GetSize() )
ret = 1;
else if( ::nl_combine[lp1].ref_des.GetSize() < ::nl_combine[lp2].ref_des.GetSize() )
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:
ret = -ret;
break;
}
return ret;
}
// CDlgNetCombine dialog
IMPLEMENT_DYNAMIC(CDlgNetCombine, CDialog)
CDlgNetCombine::CDlgNetCombine(CWnd* pParent /*=NULL*/)
: CDialog(CDlgNetCombine::IDD, pParent)
{
m_w = 0;
m_v_w = 0;
m_v_h_w = 0;
m_nlist = 0;
}
CDlgNetCombine::~CDlgNetCombine()
{
}
void CDlgNetCombine::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_LIST_NET, m_list_ctrl);
if( pDX->m_bSaveAndValidate )
{
}
}
BEGIN_MESSAGE_MAP(CDlgNetCombine, CDialog)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_NET, OnLvnColumnclickListNet)
ON_BN_CLICKED(IDOK, OnBnClickedOk)
ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
END_MESSAGE_MAP()
void CDlgNetCombine::Initialize( CNetList * nlist, CPartList * plist )
{
m_nlist = nlist;
m_plist = plist;
}
// CDlgNetCombine message handlers
BOOL CDlgNetCombine::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_combine;
m_nlist->ExportNetListInfo( m_nl );
// initialize netlist control
m_item_selected = -1;
m_sort_type = 0;
m_visible_state = 1;
DrawListCtrl();
return TRUE;
}
// draw listview control and sort according to m_sort_type
//
void CDlgNetCombine::DrawListCtrl()
{
int nItem;
CString str;
DWORD old_style = m_list_ctrl.GetExtendedStyle();
m_list_ctrl.SetExtendedStyle( LVS_EX_FULLROWSELECT | LVS_EX_FLATSB | old_style );
m_list_ctrl.DeleteAllItems();
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, 40 );
m_list_ctrl.InsertColumn( COL_VIA_W, "Via W", LVCFMT_LEFT, 40 );
m_list_ctrl.InsertColumn( COL_HOLE_W, "Hole", LVCFMT_LEFT, 40 );
int iItem = 0;
for( int i=0; i<::nl_combine.GetSize(); i++ )
{
nItem = m_list_ctrl.InsertItem( iItem, "" );
m_list_ctrl.SetItemData( iItem, (LPARAM)i );
m_list_ctrl.SetItem( iItem, COL_NAME, LVIF_TEXT, ::nl_combine[i].name, 0, 0, 0, 0 );
str.Format( "%d", ::nl_combine[i].ref_des.GetSize() );
m_list_ctrl.SetItem( iItem, COL_PINS, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::nl_combine[i].w/NM_PER_MIL );
m_list_ctrl.SetItem( iItem, COL_WIDTH, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::nl_combine[i].v_w/NM_PER_MIL );
m_list_ctrl.SetItem( iItem, COL_VIA_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::nl_combine[i].v_h_w/NM_PER_MIL );
m_list_ctrl.SetItem( iItem, COL_HOLE_W, LVIF_TEXT, str, 0, 0, 0, 0 );
ListView_SetCheckState( m_list_ctrl, nItem, ::nl_combine[i].visible );
}
m_list_ctrl.SortItems( ::CompareNetlistCombine, m_sort_type );
}
void CDlgNetCombine::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( ::CompareNetlistCombine, 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( ::CompareNetlistCombine, 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( ::CompareNetlistCombine, 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( ::CompareNetlistCombine, 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( ::CompareNetlistCombine, m_sort_type );
}
*pResult = 0;
}
void CDlgNetCombine::OnBnClickedOk()
{
char ch[41];
int n = m_list_ctrl.GetSelectedCount();
if( n == 0 )
{
AfxMessageBox( "No nets selected" );
return;
}
m_names.SetSize(n);
int i = 0;
POSITION pos = m_list_ctrl.GetFirstSelectedItemPosition();
while( pos )
{
int nItem = m_list_ctrl.GetNextSelectedItem(pos);
m_list_ctrl.GetItemText( nItem, 0, ch, 40 );
m_names[i++] = ch;
}
CDlgChooseNetName dlg;
dlg.Initialize( &m_names );
int ret = dlg.DoModal();
if( ret == IDOK )
{
m_new_name = dlg.m_sel_str;
OnOK();
}
else
{
return;
}
}
void CDlgNetCombine::OnBnClickedCancel()
{
// TODO: Add your control notification handler code here
OnCancel();
}