KiCad PCB EDA Suite
panel_setup_tracks_and_vias.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2018-2022 KiCad Developers, see change_log.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24
25#include <pcb_edit_frame.h>
27#include <bitmaps.h>
28#include <widgets/wx_grid.h>
29#include <wx/treebook.h>
30#include <grid_tricks.h>
31
33
34
36{
37 TR_WIDTH_COL = 0
38};
39
41{
44};
45
47{
51};
52
53
55 PCB_EDIT_FRAME* aFrame ) :
56 PANEL_SETUP_TRACKS_AND_VIAS_BASE( aParent->GetTreebook() )
57{
58 m_Parent = aParent;
59 m_Frame = aFrame;
62
72
73 // Membership combobox editors require a bit more room, so increase the row size of
74 // all our grids for consistency
75 m_trackWidthsGrid->SetDefaultRowSize( m_trackWidthsGrid->GetDefaultRowSize() + 4 );
76 m_viaSizesGrid->SetDefaultRowSize( m_viaSizesGrid->GetDefaultRowSize() + 4 );
77 m_diffPairsGrid->SetDefaultRowSize( m_diffPairsGrid->GetDefaultRowSize() + 4 );
78
79 m_trackWidthsGrid->PushEventHandler( new GRID_TRICKS( m_trackWidthsGrid,
80 [this]( wxCommandEvent& aEvent )
81 {
82 OnAddTrackWidthsClick( aEvent );
83 } ) );
84 m_viaSizesGrid->PushEventHandler( new GRID_TRICKS( m_viaSizesGrid,
85 [this]( wxCommandEvent& aEvent )
86 {
87 OnAddViaSizesClick( aEvent );
88 } ) );
89 m_diffPairsGrid->PushEventHandler( new GRID_TRICKS( m_diffPairsGrid,
90 [this]( wxCommandEvent& aEvent )
91 {
92 OnAddDiffPairsClick( aEvent );
93 } ) );
94
95 m_trackWidthsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
96 m_viaSizesGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
97 m_diffPairsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
98
102
104 m_viaSizesGrid->SetAutoEvalCols( { 0, 1 } );
105 m_diffPairsGrid->SetAutoEvalCols( { 0, 1, 2 } );
106
107 // Ensure width of columns is enough to enter any reasonable value
108 WX_GRID* grid_list[] = { m_trackWidthsGrid, m_viaSizesGrid, m_diffPairsGrid, nullptr };
109 int min_linesize = m_trackWidthsGrid->GetTextExtent( wxT( "000.000000 mm " ) ).x;
110
111 for( int ii = 0; grid_list[ii]; ii++ )
112 {
113 WX_GRID* curr_grid = grid_list[ii];
114
115 for( int col = 0; col < curr_grid->GetNumberCols(); col++ )
116 {
117 int min_w = curr_grid->GetVisibleWidth( col, true, true, true );
118 int best_w = std::max( min_linesize, min_w );
119 curr_grid->SetColMinimalWidth( col, best_w );
120 curr_grid->SetColSize( col,best_w );
121 }
122 }
123
124 m_Frame->Bind( UNITS_CHANGED, &PANEL_SETUP_TRACKS_AND_VIAS::onUnitsChanged, this );
125}
126
127
129{
130 // Delete the GRID_TRICKS.
131 m_trackWidthsGrid->PopEventHandler( true );
132 m_viaSizesGrid->PopEventHandler( true );
133 m_diffPairsGrid->PopEventHandler( true );
134
135 m_Frame->Unbind( UNITS_CHANGED, &PANEL_SETUP_TRACKS_AND_VIAS::onUnitsChanged, this );
136}
137
138
140{
141 std::vector<int> trackWidths;
142 wxString msg;
143
144 wxGridUpdateLocker lock( m_trackWidthsGrid );
145
146 for( int row = 0; row < m_trackWidthsGrid->GetNumberRows(); ++row )
147 {
148 msg = m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL );
149
150 if( !msg.IsEmpty() )
151 trackWidths.push_back( m_Frame->ValueFromString( msg ) );
152 }
153
154 std::sort( trackWidths.begin(), trackWidths.end() );
155 m_trackWidthsGrid->DeleteRows(0, m_trackWidthsGrid->GetNumberRows(), false);
156
157 for( int width : trackWidths )
158 AppendTrackWidth( width );
159}
160
161
163{
164 std::vector<VIA_DIMENSION> vias;
165 wxString msg;
166
167 wxGridUpdateLocker lock( m_viaSizesGrid );
168
169 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
170 {
171 msg = m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL );
172
173 if( !msg.IsEmpty() )
174 {
175 VIA_DIMENSION via_dim;
176 via_dim.m_Diameter = m_Frame->ValueFromString( msg );
177
178 msg = m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL );
179
180 if( !msg.IsEmpty() )
181 via_dim.m_Drill = m_Frame->ValueFromString( msg );
182
183 vias.push_back( via_dim );
184 }
185 }
186
187 std::sort( vias.begin(), vias.end() );
188 m_viaSizesGrid->DeleteRows(0, m_viaSizesGrid->GetNumberRows(), false );
189
190 for( const VIA_DIMENSION& via : vias )
191 AppendViaSize( via.m_Diameter, via.m_Drill );
192}
193
194
196{
197 wxString msg;
198 std::vector<DIFF_PAIR_DIMENSION> diffPairs;
199
200 wxGridUpdateLocker lock( m_diffPairsGrid );
201
202 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
203 {
204 msg = m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL );
205
206 if( !msg.IsEmpty() )
207 {
208 DIFF_PAIR_DIMENSION diffPair_dim;
209 diffPair_dim.m_Width = m_Frame->ValueFromString( msg );
210
211 msg = m_diffPairsGrid->GetCellValue( row, DP_GAP_COL );
212 diffPair_dim.m_Gap = m_Frame->ValueFromString( msg );
213
214 msg = m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL );
215
216 if( !msg.IsEmpty() )
217 diffPair_dim.m_ViaGap = m_Frame->ValueFromString( msg );
218
219 diffPairs.push_back( diffPair_dim );
220 }
221 }
222
223 std::sort( diffPairs.begin(), diffPairs.end() );
224 m_diffPairsGrid->DeleteRows(0, m_diffPairsGrid->GetNumberRows(), false );
225
226 for( const DIFF_PAIR_DIMENSION& dp : diffPairs )
227 AppendDiffPairs( dp.m_Width, dp.m_Gap, dp.m_ViaGap );
228}
229
230
232{
233 BOARD_DESIGN_SETTINGS tempBDS( nullptr, "dummy" );
235
236 m_BrdSettings = &tempBDS; // No, address of stack var does not escape function
237
240
241 m_BrdSettings = saveBDS;
242
243 aEvent.Skip();
244}
245
246
248{
252
253 // Skip the first item, which is the current netclass value
254 for( unsigned ii = 1; ii < m_BrdSettings->m_TrackWidthList.size(); ii++ )
255 {
257 }
258
259 // Skip the first item, which is the current netclass value
260 for( unsigned ii = 1; ii < m_BrdSettings->m_ViasDimensionsList.size(); ii++ )
261 {
263 m_BrdSettings->m_ViasDimensionsList[ii].m_Drill );
264 }
265
266 // Skip the first item, which is the current netclass value
267 for( unsigned ii = 1; ii < m_BrdSettings->m_DiffPairDimensionsList.size(); ii++ )
268 {
272 }
273
274 return true;
275}
276
277
279{
283 {
284 return false;
285 }
286
287 wxString msg;
288 std::vector<int> trackWidths;
289 std::vector<VIA_DIMENSION> vias;
290 std::vector<DIFF_PAIR_DIMENSION> diffPairs;
291
292 // Test ONLY for malformed data. Design rules and constraints are the business of DRC.
293
294 for( int row = 0; row < m_trackWidthsGrid->GetNumberRows(); ++row )
295 {
296 if( !m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL ).IsEmpty() )
297 trackWidths.push_back( m_trackWidthsGrid->GetUnitValue( row, TR_WIDTH_COL ) );
298 }
299
300 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
301 {
302 if( !m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL ).IsEmpty() )
303 {
304 VIA_DIMENSION via_dim;
306
307 if( !m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL ).IsEmpty() )
309
310 vias.push_back( via_dim );
311 }
312 }
313
314 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
315 {
316 if( !m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL ).IsEmpty() )
317 {
318 DIFF_PAIR_DIMENSION diffPair_dim;
319 diffPair_dim.m_Width = m_diffPairsGrid->GetUnitValue( row, DP_WIDTH_COL );
320
321 if( !m_diffPairsGrid->GetCellValue( row, DP_GAP_COL ).IsEmpty() )
322 diffPair_dim.m_Gap = m_diffPairsGrid->GetUnitValue( row, DP_GAP_COL );
323
324 if( !m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL ).IsEmpty() )
325 diffPair_dim.m_ViaGap = m_diffPairsGrid->GetUnitValue( row, DP_VIA_GAP_COL );
326
327 diffPairs.push_back( diffPair_dim );
328 }
329 }
330
331 // Sort lists by increasing value
332 sort( trackWidths.begin(), trackWidths.end() );
333 sort( vias.begin(), vias.end() );
334 sort( diffPairs.begin(), diffPairs.end() );
335
336 // These are all stored in project file, not board, so no need for OnModify()
337
338 trackWidths.insert( trackWidths.begin(), 0 ); // dummy value for "use netclass"
339 m_BrdSettings->m_TrackWidthList = trackWidths;
340
341 vias.insert( vias.begin(), { 0, 0 } ); // dummy value for "use netclass"
343
344 diffPairs.insert( diffPairs.begin(), { 0, 0, 0 } ); // dummy value for "use netclass"
346
347 return true;
348}
349
350
352{
356 {
357 return false;
358 }
359
360 wxString msg;
361
362 // Test vias
363 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
364 {
365 wxString viaDia = m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL );
366 wxString viaDrill = m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL );
367
368 if( !viaDia.IsEmpty() && viaDrill.IsEmpty() )
369 {
370 msg = _( "No via hole size defined." );
371 m_Parent->SetError( msg, this, m_viaSizesGrid, row, VIA_DRILL_COL );
372 return false;
373 }
374 }
375
376 // Test diff pairs
377 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
378 {
379 wxString dpWidth = m_diffPairsGrid->GetCellValue( row, 0 );
380 wxString dpGap = m_diffPairsGrid->GetCellValue( row, 1 );
381
382 if( !dpWidth.IsEmpty() && dpGap.IsEmpty() )
383 {
384 msg = _( "No differential pair gap defined." );
385 m_Parent->SetError( msg, this, m_diffPairsGrid, row, 1 );
386 return false;
387 }
388 }
389
390 return true;
391}
392
393
395{
396 int i = m_trackWidthsGrid->GetNumberRows();
397
398 m_trackWidthsGrid->AppendRows( 1 );
399
401}
402
403
405{
406 int i = m_viaSizesGrid->GetNumberRows();
407
408 m_viaSizesGrid->AppendRows( 1 );
409
411
412 if( aDrill > 0 )
414}
415
416
417void PANEL_SETUP_TRACKS_AND_VIAS::AppendDiffPairs( int aWidth, int aGap, int aViaGap )
418{
419 int i = m_diffPairsGrid->GetNumberRows();
420
421 m_diffPairsGrid->AppendRows( 1 );
422
424
425 if( aGap > 0 )
427
428 if( aViaGap > 0 )
430}
431
432
434{
435 wxArrayInt selectedRows = aGrid->GetSelectedRows();
436 int curRow = aGrid->GetGridCursorRow();
437
438 if( selectedRows.empty() && curRow >= 0 && curRow < aGrid->GetNumberRows() )
439 selectedRows.Add( curRow );
440
441 for( int ii = selectedRows.Count() - 1; ii >= 0; --ii )
442 {
443 int row = selectedRows.Item( ii );
444 aGrid->DeleteRows( row, 1 );
445 curRow = std::min( curRow, row );
446 }
447
448 curRow = std::max( 0, curRow - 1 );
449 aGrid->MakeCellVisible( curRow, aGrid->GetGridCursorCol() );
450 aGrid->SetGridCursor( curRow, aGrid->GetGridCursorCol() );
451}
452
453
455{
459 {
460 return;
461 }
462
463 AppendTrackWidth( 0 );
464
465 m_trackWidthsGrid->MakeCellVisible( m_trackWidthsGrid->GetNumberRows() - 1, TR_WIDTH_COL );
466 m_trackWidthsGrid->SetGridCursor( m_trackWidthsGrid->GetNumberRows() - 1, TR_WIDTH_COL );
467
468 m_trackWidthsGrid->EnableCellEditControl( true );
469 m_trackWidthsGrid->ShowCellEditControl();
470}
471
472
474{
478 {
479 return;
480 }
481
483}
484
485
487{
491 {
492 return;
493 }
494
495 AppendViaSize( 0, 0 );
496
497 m_viaSizesGrid->MakeCellVisible( m_viaSizesGrid->GetNumberRows() - 1, VIA_SIZE_COL );
498 m_viaSizesGrid->SetGridCursor( m_viaSizesGrid->GetNumberRows() - 1, VIA_SIZE_COL );
499
500 m_viaSizesGrid->EnableCellEditControl( true );
501 m_viaSizesGrid->ShowCellEditControl();
502}
503
504
506{
510 {
511 return;
512 }
513
515}
516
517
519{
523 {
524 return;
525 }
526
527 AppendDiffPairs( 0, 0, 0 );
528
529 m_diffPairsGrid->MakeCellVisible( m_diffPairsGrid->GetNumberRows() - 1, DP_WIDTH_COL );
530 m_diffPairsGrid->SetGridCursor( m_diffPairsGrid->GetNumberRows() - 1, DP_WIDTH_COL );
531
532 m_diffPairsGrid->EnableCellEditControl( true );
533 m_diffPairsGrid->ShowCellEditControl();
534}
535
536
538{
542 {
543 return;
544 }
545
547}
548
549
551{
555
556 // Note: do not change the board, as we need to get the current nets from it for
557 // netclass memberships. All the netclass definitions and dimension lists are in
558 // the BOARD_DESIGN_SETTINGS.
559
560 BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
561
562 m_BrdSettings = &aBoard->GetDesignSettings();
564
565 m_BrdSettings = savedSettings;
566}
567
wxBitmap KiBitmap(BITMAPS aBitmap, int aHeightTag)
Construct a wxBitmap from an image identifier Returns the image from the active theme if the image ha...
Definition: bitmap.cpp:105
@ small_sort_desc
Container for design settings for a BOARD object.
std::vector< DIFF_PAIR_DIMENSION > m_DiffPairDimensionsList
std::vector< int > m_TrackWidthList
std::vector< VIA_DIMENSION > m_ViasDimensionsList
Information pertinent to a Pcbnew printed circuit board.
Definition: board.h:265
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:628
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
void SetError(const wxString &aMessage, const wxString &aPageName, int aCtrlId, int aRow=-1, int aCol=-1)
Class PANEL_SETUP_TRACKS_AND_VIAS_BASE.
void OnRemoveViaSizesClick(wxCommandEvent &event) override
void OnRemoveDiffPairsClick(wxCommandEvent &event) override
void OnSortTrackWidthsClick(wxCommandEvent &event) override
void onUnitsChanged(wxCommandEvent &aEvent)
void OnSortViaSizesClick(wxCommandEvent &event) override
void OnAddViaSizesClick(wxCommandEvent &event) override
void OnSortDiffPairsClick(wxCommandEvent &event) override
void OnRemoveTrackWidthsClick(wxCommandEvent &event) override
void OnAddDiffPairsClick(wxCommandEvent &event) override
void AppendDiffPairs(int aWidth, int aGap, int aViaGap)
void OnAddTrackWidthsClick(wxCommandEvent &event) override
PANEL_SETUP_TRACKS_AND_VIAS(PAGED_DIALOG *aParent, PCB_EDIT_FRAME *aFrame)
void AppendViaSize(int aSize, int aDrill)
BOARD * GetBoard() const
The main frame for Pcbnew.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE)
Converts aTextValue in aUnits to internal units used by the frame.
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:377
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:359
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:338
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:90
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:329
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:133
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:280
#define _(s)
void removeSelectedRows(WX_GRID *aGrid)
Container to handle a stock of specific differential pairs each with unique track width,...
Container to handle a stock of specific vias each with unique diameter and drill sizes in the BOARD c...