forked from jpt13653903/FreePCB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DlgGroupPaste.cpp
400 lines (367 loc) · 10.4 KB
/
DlgGroupPaste.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
// DlgGroupPaste.cpp : implementation file
//
#include "stdafx.h"
#include "FreePcb.h"
#include "DlgGroupPaste.h"
// columns for list
enum {
COL_VIS = 0,
COL_NAME,
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 ListCompare() for sorting list control items
netlist_info gnl;
// global callback function for sorting
// lp1, lp2 are indexes to global arrays above
//
int CALLBACK ListCompare( LPARAM lp1, LPARAM lp2, LPARAM type )
{
int ret = 0;
switch( type )
{
case SORT_UP_NAME:
case SORT_DOWN_NAME:
ret = (strcmp( ::gnl[lp1].name, ::gnl[lp2].name ));
break;
case SORT_UP_WIDTH:
case SORT_DOWN_WIDTH:
if( ::gnl[lp1].w > ::gnl[lp2].w )
ret = 1;
else if( ::gnl[lp1].w < ::gnl[lp2].w )
ret = -1;
break;
case SORT_UP_VIA_W:
case SORT_DOWN_VIA_W:
if( ::gnl[lp1].v_w > ::gnl[lp2].v_w )
ret = 1;
else if( ::gnl[lp1].v_w < ::gnl[lp2].v_w )
ret = -1;
break;
case SORT_UP_HOLE_W:
case SORT_DOWN_HOLE_W:
if( ::gnl[lp1].v_h_w > ::gnl[lp2].v_h_w )
ret = 1;
else if( ::gnl[lp1].v_h_w < ::gnl[lp2].v_h_w )
ret = -1;
break;
case SORT_UP_PINS:
case SORT_DOWN_PINS:
if( ::gnl[lp1].ref_des.GetSize() > ::gnl[lp2].ref_des.GetSize() )
ret = 1;
else if( ::gnl[lp1].ref_des.GetSize() < ::gnl[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;
}
// CDlgGroupPaste dialog
IMPLEMENT_DYNAMIC(CDlgGroupPaste, CDialog)
CDlgGroupPaste::CDlgGroupPaste(CWnd* pParent /*=NULL*/)
: CDialog(CDlgGroupPaste::IDD, pParent)
{
}
CDlgGroupPaste::~CDlgGroupPaste()
{
}
void CDlgGroupPaste::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
DDX_Control(pDX, IDC_RADIO_USE_GROUP_REF, m_radio_use_group_ref);
DDX_Control(pDX, IDC_RADIO_USE_NEXT_REF, m_radio_use_next_ref);
DDX_Control(pDX, IDC_RADIO_ADD_REF_OFFSET, m_radio_add_ref_offset);
DDX_Control(pDX, IDC_EDIT_REF_OFFSET, m_edit_offset);
DDX_Control(pDX, IDC_RADIO_USE_GROUP_NETS, m_radio_use_group_nets);
DDX_Control(pDX, IDC_RADIO_USE_SELECTED_NETS, m_radio_use_selected_nets);
DDX_Control(pDX, IDC_LIST_SELECT_GROUP_NETS, m_list_ctrl);
DDX_Control(pDX, IDC_RADIO_USE_SUFFIX, m_radio_use_suffix);
DDX_Control(pDX, IDC_RADIO_MAKE_NEW_NAMES, m_radio_make_new_names);
DDX_Control(pDX, IDC_RADIO_DRAG, m_radio_drag);
DDX_Control(pDX, IDC_RADIO_OFFSET, m_radio_offset);
DDX_Control(pDX, IDC_EDIT_GROUP_X, m_edit_x);
DDX_Control(pDX, IDC_EDIT_GROUP_Y, m_edit_y);
DDX_Control(pDX, IDC_COMBO_GROUP_UNITS, m_combo_units);
DDX_Control(pDX, IDC_RADIO_RETAIN_ALL, m_radio_retain_all_nets);
DDX_Control(pDX, IDC_RADIO_RETAIN_TRACES, m_radio_retain_traces);
DDX_Text( pDX, IDC_EDIT_GROUP_X, m_dx );
DDX_Text( pDX, IDC_EDIT_GROUP_Y, m_dy );
DDX_Text( pDX, IDC_EDIT_REF_OFFSET, m_ref_offset );
if( !pDX->m_bSaveAndValidate )
{
// incoming
m_sort_type = 0;
m_radio_use_next_ref.SetCheck(1);
m_radio_use_selected_nets.SetCheck(1);
m_radio_use_suffix.SetCheck(1);
m_radio_drag.SetCheck(1);
m_radio_retain_all_nets.SetCheck(1);
m_combo_units.AddString( "MM" );
m_combo_units.AddString( "MIL" );
m_combo_units.SelectString( 0, "MIL" );
SetFields();
// now set up listview control
int nItem;
LVITEM lvitem;
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.InsertColumn( COL_VIS, "Sel", LVCFMT_LEFT, 30 );
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 );
for( int i=0; i<gnl.GetSize(); i++ )
{
lvitem.mask = LVIF_TEXT | LVIF_PARAM;
lvitem.pszText = "";
lvitem.lParam = i;
nItem = m_list_ctrl.InsertItem( i, "" );
m_list_ctrl.SetItemData( i, (LPARAM)i );
m_list_ctrl.SetItem( i, COL_NAME, LVIF_TEXT, ::gnl[i].name, 0, 0, 0, 0 );
str.Format( "%d", ::gnl[i].ref_des.GetSize() );
m_list_ctrl.SetItem( i, COL_PINS, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::gnl[i].w/NM_PER_MIL );
m_list_ctrl.SetItem( i, COL_WIDTH, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::gnl[i].v_w/NM_PER_MIL );
m_list_ctrl.SetItem( i, COL_VIA_W, LVIF_TEXT, str, 0, 0, 0, 0 );
str.Format( "%d", ::gnl[i].v_h_w/NM_PER_MIL );
m_list_ctrl.SetItem( i, COL_HOLE_W, LVIF_TEXT, str, 0, 0, 0, 0 );
ListView_SetCheckState( m_list_ctrl, nItem, 0 );
}
}
else
{
// outgoing
SetFields();
CString str;
m_combo_units.GetWindowText( str );
if( str == "MIL" )
{
m_dx *= NM_PER_MIL;
m_dy *= NM_PER_MIL;
}
else
{
m_dx *= 1000000;
m_dy *= 1000000;
}
// export data into netlist
for( int iItem=0; iItem<m_list_ctrl.GetItemCount(); iItem++ )
{
int i = m_list_ctrl.GetItemData( iItem );
CString * net_name = &::gnl[i].name;
cnet * grp_net = m_grp_nlist->GetNetPtrByName( net_name );
if( grp_net == NULL )
ASSERT(0);
grp_net->utility = ListView_GetCheckState( m_list_ctrl, iItem );
}
::gnl.SetSize(0);
}
}
BEGIN_MESSAGE_MAP(CDlgGroupPaste, CDialog)
ON_BN_CLICKED(IDC_RADIO_USE_GROUP_REF, OnBnClickedRadioUseGroupRef)
ON_BN_CLICKED(IDC_RADIO_USE_NEXT_REF, OnBnClickedRadioUseNextRef)
ON_BN_CLICKED(IDC_RADIO_ADD_REF_OFFSET, OnBnClickedRadioAddRefOffset)
ON_BN_CLICKED(IDC_RADIO_USE_GROUP_NETS, OnBnClickedRadioUseGroupNets)
ON_BN_CLICKED(IDC_RADIO_USE_SELECTED_NETS, OnBnClickedRadioUseSelectedNets)
ON_BN_CLICKED(IDC_RADIO_USE_SUFFIX, OnBnClickedRadioUseSuffix)
ON_BN_CLICKED(IDC_RADIO_MAKE_NEW_NAMES, OnBnClickedRadioMakeNewNames)
ON_BN_CLICKED(IDC_RADIO_DRAG, OnBnClickedRadioDrag)
ON_BN_CLICKED(IDC_RADIO_OFFSET, OnBnClickedRadioOffset)
ON_CBN_SELCHANGE(IDC_COMBO_GROUP_UNITS, OnCbnSelchangeComboGroupUnits)
ON_BN_CLICKED(IDC_RADIO_RETAIN_ALL, OnBnClickedRadioRetainAll)
ON_BN_CLICKED(IDC_RADIO_RETAIN_TRACES, OnBnClickedRadioRetainTraces)
ON_NOTIFY(LVN_COLUMNCLICK, IDC_LIST_SELECT_GROUP_NETS, OnLvnColumnClickListSelectGroupNets)
END_MESSAGE_MAP()
void CDlgGroupPaste::Initialize( CNetList * grp_nlist )
{
m_grp_nlist = grp_nlist;
m_ref_offset = 0;
m_dx = 0;
m_dy = 0;
grp_nlist->ExportNetListInfo( &gnl );
}
void CDlgGroupPaste::SetFields()
{
// set values and enable/disable items based on selections
if( m_radio_use_group_ref.GetCheck() )
{
m_ref_option = 0;
m_edit_offset.EnableWindow(0);
}
else if( m_radio_use_next_ref.GetCheck() )
{
m_ref_option = 1;
m_edit_offset.EnableWindow(0);
}
else if( m_radio_add_ref_offset.GetCheck() )
{
m_ref_option = 2;
m_edit_offset.EnableWindow(1);
}
if( m_radio_use_group_nets.GetCheck() )
{
m_net_name_option = 0;
m_list_ctrl.EnableWindow(0);
m_radio_use_suffix.EnableWindow(0);
m_radio_make_new_names.EnableWindow(0);
}
else if( m_radio_use_selected_nets.GetCheck() )
{
m_net_name_option = 1;
m_list_ctrl.EnableWindow(1);
m_radio_use_suffix.EnableWindow(1);
m_radio_make_new_names.EnableWindow(1);
}
if( m_radio_drag.GetCheck() )
{
m_position_option = 0;
m_edit_x.EnableWindow(0);
m_edit_y.EnableWindow(0);
m_combo_units.EnableWindow(0);
}
else if( m_radio_offset.GetCheck() )
{
m_position_option = 1;
m_edit_x.EnableWindow(1);
m_edit_y.EnableWindow(1);
m_combo_units.EnableWindow(1);
}
if( m_radio_use_suffix.GetCheck() )
{
m_net_rename_option = 0;
}
else if( m_radio_make_new_names.GetCheck() )
{
m_net_rename_option = 1;
}
if( m_radio_retain_all_nets.GetCheck() )
{
m_pin_net_option = 0;
}
else
{
m_pin_net_option = 1;
}
}
// CDlgGroupPaste message handlers
void CDlgGroupPaste::OnBnClickedRadioUseGroupRef()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioUseNextRef()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioAddRefOffset()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioUseGroupNets()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioUseSelectedNets()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioUseSuffix()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioMakeNewNames()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioDrag()
{
SetFields();
}
void CDlgGroupPaste::OnBnClickedRadioOffset()
{
SetFields();
}
void CDlgGroupPaste::OnCbnSelchangeComboGroupUnits()
{
// TODO: Add your control notification handler code here
}
void CDlgGroupPaste::OnBnClickedRadioRetainAll()
{
// TODO: Add your control notification handler code here
}
void CDlgGroupPaste::OnBnClickedRadioRetainTraces()
{
// TODO: Add your control notification handler code here
}
void CDlgGroupPaste::OnLvnColumnClickListSelectGroupNets(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( ::ListCompare, 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( ::ListCompare, 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( ::ListCompare, 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( ::ListCompare, 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( ::ListCompare, m_sort_type );
}
*pResult = 0;
}