KiCad PCB EDA Suite
Loading...
Searching...
No Matches
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-2023 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>
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 ) :
57{
58 m_Frame = aFrame;
61
62 m_trackWidthsAddButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
63 m_trackWidthsSortButton->SetBitmap( KiBitmap( BITMAPS::small_sort_desc ) );
64 m_trackWidthsRemoveButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
65 m_viaSizesAddButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
66 m_viaSizesSortButton->SetBitmap( KiBitmap( BITMAPS::small_sort_desc ) );
67 m_viaSizesRemoveButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
68 m_diffPairsAddButton->SetBitmap( KiBitmap( BITMAPS::small_plus ) );
69 m_diffPairsSortButton->SetBitmap( KiBitmap( BITMAPS::small_sort_desc ) );
70 m_diffPairsRemoveButton->SetBitmap( KiBitmap( BITMAPS::small_trash ) );
71
72 // Membership combobox editors require a bit more room, so increase the row size of
73 // all our grids for consistency
74 m_trackWidthsGrid->SetDefaultRowSize( m_trackWidthsGrid->GetDefaultRowSize() + 4 );
75 m_viaSizesGrid->SetDefaultRowSize( m_viaSizesGrid->GetDefaultRowSize() + 4 );
76 m_diffPairsGrid->SetDefaultRowSize( m_diffPairsGrid->GetDefaultRowSize() + 4 );
77
78 m_trackWidthsGrid->PushEventHandler( new GRID_TRICKS( m_trackWidthsGrid,
79 [this]( wxCommandEvent& aEvent )
80 {
81 OnAddTrackWidthsClick( aEvent );
82 } ) );
83 m_viaSizesGrid->PushEventHandler( new GRID_TRICKS( m_viaSizesGrid,
84 [this]( wxCommandEvent& aEvent )
85 {
86 OnAddViaSizesClick( aEvent );
87 } ) );
88 m_diffPairsGrid->PushEventHandler( new GRID_TRICKS( m_diffPairsGrid,
89 [this]( wxCommandEvent& aEvent )
90 {
91 OnAddDiffPairsClick( aEvent );
92 } ) );
93
94 m_trackWidthsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
95 m_viaSizesGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
96 m_diffPairsGrid->SetSelectionMode( wxGrid::wxGridSelectionModes::wxGridSelectRows );
97
101
103 m_viaSizesGrid->SetAutoEvalCols( { 0, 1 } );
104 m_diffPairsGrid->SetAutoEvalCols( { 0, 1, 2 } );
105
106 // Ensure width of columns is enough to enter any reasonable value
107 WX_GRID* grid_list[] = { m_trackWidthsGrid, m_viaSizesGrid, m_diffPairsGrid, nullptr };
108 int min_linesize = m_trackWidthsGrid->GetTextExtent( wxT( "000.000000 mm " ) ).x;
109
110 for( int ii = 0; grid_list[ii]; ii++ )
111 {
112 WX_GRID* curr_grid = grid_list[ii];
113
114 for( int col = 0; col < curr_grid->GetNumberCols(); col++ )
115 {
116 int min_w = curr_grid->GetVisibleWidth( col, true, true, true );
117 int best_w = std::max( min_linesize, min_w );
118 curr_grid->SetColMinimalWidth( col, best_w );
119 curr_grid->SetColSize( col,best_w );
120 }
121 }
122
123 m_Frame->Bind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_TRACKS_AND_VIAS::onUnitsChanged, this );
124}
125
126
128{
129 // Delete the GRID_TRICKS.
130 m_trackWidthsGrid->PopEventHandler( true );
131 m_viaSizesGrid->PopEventHandler( true );
132 m_diffPairsGrid->PopEventHandler( true );
133
134 m_Frame->Unbind( EDA_EVT_UNITS_CHANGED, &PANEL_SETUP_TRACKS_AND_VIAS::onUnitsChanged, this );
135}
136
137
139{
140 std::vector<int> trackWidths;
141 wxString msg;
142
143 wxGridUpdateLocker lock( m_trackWidthsGrid );
144
145 for( int row = 0; row < m_trackWidthsGrid->GetNumberRows(); ++row )
146 {
147 msg = m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL );
148
149 if( !msg.IsEmpty() )
150 trackWidths.push_back( m_Frame->ValueFromString( msg ) );
151 }
152
153 std::sort( trackWidths.begin(), trackWidths.end() );
154 m_trackWidthsGrid->DeleteRows(0, m_trackWidthsGrid->GetNumberRows(), false);
155
156 for( int width : trackWidths )
157 AppendTrackWidth( width );
158}
159
160
162{
163 std::vector<VIA_DIMENSION> vias;
164 wxString msg;
165
166 wxGridUpdateLocker lock( m_viaSizesGrid );
167
168 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
169 {
170 msg = m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL );
171
172 if( !msg.IsEmpty() )
173 {
174 VIA_DIMENSION via_dim;
175 via_dim.m_Diameter = m_Frame->ValueFromString( msg );
176
177 msg = m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL );
178
179 if( !msg.IsEmpty() )
180 via_dim.m_Drill = m_Frame->ValueFromString( msg );
181
182 vias.push_back( via_dim );
183 }
184 }
185
186 std::sort( vias.begin(), vias.end() );
187 m_viaSizesGrid->DeleteRows(0, m_viaSizesGrid->GetNumberRows(), false );
188
189 for( const VIA_DIMENSION& via : vias )
190 AppendViaSize( via.m_Diameter, via.m_Drill );
191}
192
193
195{
196 wxString msg;
197 std::vector<DIFF_PAIR_DIMENSION> diffPairs;
198
199 wxGridUpdateLocker lock( m_diffPairsGrid );
200
201 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
202 {
203 msg = m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL );
204
205 if( !msg.IsEmpty() )
206 {
207 DIFF_PAIR_DIMENSION diffPair_dim;
208 diffPair_dim.m_Width = m_Frame->ValueFromString( msg );
209
210 msg = m_diffPairsGrid->GetCellValue( row, DP_GAP_COL );
211 diffPair_dim.m_Gap = m_Frame->ValueFromString( msg );
212
213 msg = m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL );
214
215 if( !msg.IsEmpty() )
216 diffPair_dim.m_ViaGap = m_Frame->ValueFromString( msg );
217
218 diffPairs.push_back( diffPair_dim );
219 }
220 }
221
222 std::sort( diffPairs.begin(), diffPairs.end() );
223 m_diffPairsGrid->DeleteRows(0, m_diffPairsGrid->GetNumberRows(), false );
224
225 for( const DIFF_PAIR_DIMENSION& dp : diffPairs )
226 AppendDiffPairs( dp.m_Width, dp.m_Gap, dp.m_ViaGap );
227}
228
229
231{
232 BOARD_DESIGN_SETTINGS tempBDS( nullptr, "dummy" );
234
235 m_BrdSettings = &tempBDS; // No, address of stack var does not escape function
236
239
240 m_BrdSettings = saveBDS;
241
242 aEvent.Skip();
243}
244
245
247{
251
252 // Skip the first item, which is the current netclass value
253 for( unsigned ii = 1; ii < m_BrdSettings->m_TrackWidthList.size(); ii++ )
254 {
256 }
257
258 // Skip the first item, which is the current netclass value
259 for( unsigned ii = 1; ii < m_BrdSettings->m_ViasDimensionsList.size(); ii++ )
260 {
262 m_BrdSettings->m_ViasDimensionsList[ii].m_Drill );
263 }
264
265 // Skip the first item, which is the current netclass value
266 for( unsigned ii = 1; ii < m_BrdSettings->m_DiffPairDimensionsList.size(); ii++ )
267 {
271 }
272
273 return true;
274}
275
276
278{
282 {
283 return false;
284 }
285
286 wxString msg;
287 std::vector<int> trackWidths;
288 std::vector<VIA_DIMENSION> vias;
289 std::vector<DIFF_PAIR_DIMENSION> diffPairs;
290
291 // Test ONLY for malformed data. Design rules and constraints are the business of DRC.
292
293 for( int row = 0; row < m_trackWidthsGrid->GetNumberRows(); ++row )
294 {
295 if( !m_trackWidthsGrid->GetCellValue( row, TR_WIDTH_COL ).IsEmpty() )
296 trackWidths.push_back( m_trackWidthsGrid->GetUnitValue( row, TR_WIDTH_COL ) );
297 }
298
299 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
300 {
301 if( !m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL ).IsEmpty() )
302 {
303 VIA_DIMENSION via_dim;
305
306 if( !m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL ).IsEmpty() )
308
309 vias.push_back( via_dim );
310 }
311 }
312
313 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
314 {
315 if( !m_diffPairsGrid->GetCellValue( row, DP_WIDTH_COL ).IsEmpty() )
316 {
317 DIFF_PAIR_DIMENSION diffPair_dim;
318 diffPair_dim.m_Width = m_diffPairsGrid->GetUnitValue( row, DP_WIDTH_COL );
319
320 if( !m_diffPairsGrid->GetCellValue( row, DP_GAP_COL ).IsEmpty() )
321 diffPair_dim.m_Gap = m_diffPairsGrid->GetUnitValue( row, DP_GAP_COL );
322
323 if( !m_diffPairsGrid->GetCellValue( row, DP_VIA_GAP_COL ).IsEmpty() )
324 diffPair_dim.m_ViaGap = m_diffPairsGrid->GetUnitValue( row, DP_VIA_GAP_COL );
325
326 diffPairs.push_back( diffPair_dim );
327 }
328 }
329
330 // Sort lists by increasing value
331 sort( trackWidths.begin(), trackWidths.end() );
332 sort( vias.begin(), vias.end() );
333 sort( diffPairs.begin(), diffPairs.end() );
334
335 // These are all stored in project file, not board, so no need for OnModify()
336
337 trackWidths.insert( trackWidths.begin(), 0 ); // dummy value for "use netclass"
338 m_BrdSettings->m_TrackWidthList = trackWidths;
339
340 vias.insert( vias.begin(), { 0, 0 } ); // dummy value for "use netclass"
342
343 diffPairs.insert( diffPairs.begin(), { 0, 0, 0 } ); // dummy value for "use netclass"
345
346 return true;
347}
348
349
351{
355 {
356 return false;
357 }
358
359 wxString msg;
360
361 // Test vias
362 for( int row = 0; row < m_viaSizesGrid->GetNumberRows(); ++row )
363 {
364 wxString viaDia = m_viaSizesGrid->GetCellValue( row, VIA_SIZE_COL );
365 wxString viaDrill = m_viaSizesGrid->GetCellValue( row, VIA_DRILL_COL );
366
367 if( !viaDia.IsEmpty() && viaDrill.IsEmpty() )
368 {
369 msg = _( "No via hole size defined." );
371 return false;
372 }
373 }
374
375 // Test diff pairs
376 for( int row = 0; row < m_diffPairsGrid->GetNumberRows(); ++row )
377 {
378 wxString dpWidth = m_diffPairsGrid->GetCellValue( row, 0 );
379 wxString dpGap = m_diffPairsGrid->GetCellValue( row, 1 );
380
381 if( !dpWidth.IsEmpty() && dpGap.IsEmpty() )
382 {
383 msg = _( "No differential pair gap defined." );
384 PAGED_DIALOG::GetDialog( this )->SetError( msg, this, m_diffPairsGrid, row, 1 );
385 return false;
386 }
387 }
388
389 return true;
390}
391
392
394{
395 int i = m_trackWidthsGrid->GetNumberRows();
396
397 m_trackWidthsGrid->AppendRows( 1 );
398
400}
401
402
404{
405 int i = m_viaSizesGrid->GetNumberRows();
406
407 m_viaSizesGrid->AppendRows( 1 );
408
410
411 if( aDrill > 0 )
413}
414
415
416void PANEL_SETUP_TRACKS_AND_VIAS::AppendDiffPairs( int aWidth, int aGap, int aViaGap )
417{
418 int i = m_diffPairsGrid->GetNumberRows();
419
420 m_diffPairsGrid->AppendRows( 1 );
421
423
424 if( aGap > 0 )
426
427 if( aViaGap > 0 )
429}
430
431
433{
434 wxArrayInt selectedRows = aGrid->GetSelectedRows();
435 int curRow = aGrid->GetGridCursorRow();
436
437 if( selectedRows.empty() && curRow >= 0 && curRow < aGrid->GetNumberRows() )
438 selectedRows.Add( curRow );
439
440 for( int ii = selectedRows.Count() - 1; ii >= 0; --ii )
441 {
442 int row = selectedRows.Item( ii );
443 aGrid->DeleteRows( row, 1 );
444 curRow = std::min( curRow, row );
445 }
446
447 curRow = std::max( 0, curRow - 1 );
448 aGrid->MakeCellVisible( curRow, aGrid->GetGridCursorCol() );
449 aGrid->SetGridCursor( curRow, aGrid->GetGridCursorCol() );
450}
451
452
454{
458 {
459 return;
460 }
461
462 AppendTrackWidth( 0 );
463
464 m_trackWidthsGrid->MakeCellVisible( m_trackWidthsGrid->GetNumberRows() - 1, TR_WIDTH_COL );
465 m_trackWidthsGrid->SetGridCursor( m_trackWidthsGrid->GetNumberRows() - 1, TR_WIDTH_COL );
466
467 m_trackWidthsGrid->EnableCellEditControl( true );
468 m_trackWidthsGrid->ShowCellEditControl();
469}
470
471
473{
477 {
478 return;
479 }
480
482}
483
484
486{
490 {
491 return;
492 }
493
494 AppendViaSize( 0, 0 );
495
496 m_viaSizesGrid->MakeCellVisible( m_viaSizesGrid->GetNumberRows() - 1, VIA_SIZE_COL );
497 m_viaSizesGrid->SetGridCursor( m_viaSizesGrid->GetNumberRows() - 1, VIA_SIZE_COL );
498
499 m_viaSizesGrid->EnableCellEditControl( true );
500 m_viaSizesGrid->ShowCellEditControl();
501}
502
503
505{
509 {
510 return;
511 }
512
514}
515
516
518{
522 {
523 return;
524 }
525
526 AppendDiffPairs( 0, 0, 0 );
527
528 m_diffPairsGrid->MakeCellVisible( m_diffPairsGrid->GetNumberRows() - 1, DP_WIDTH_COL );
529 m_diffPairsGrid->SetGridCursor( m_diffPairsGrid->GetNumberRows() - 1, DP_WIDTH_COL );
530
531 m_diffPairsGrid->EnableCellEditControl( true );
532 m_diffPairsGrid->ShowCellEditControl();
533}
534
535
537{
541 {
542 return;
543 }
544
546}
547
548
550{
554
555 // Note: do not change the board, as we need to get the current nets from it for
556 // netclass memberships. All the netclass definitions and dimension lists are in
557 // the BOARD_DESIGN_SETTINGS.
558
559 BOARD_DESIGN_SETTINGS* savedSettings = m_BrdSettings;
560
561 m_BrdSettings = &aBoard->GetDesignSettings();
563
564 m_BrdSettings = savedSettings;
565}
566
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:106
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:271
BOARD_DESIGN_SETTINGS & GetDesignSettings() const
Definition: board.cpp:731
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
static PAGED_DIALOG * GetDialog(wxWindow *aWindow)
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
PANEL_SETUP_TRACKS_AND_VIAS(wxWindow *aParentWindow, PCB_EDIT_FRAME *aFrame)
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
void AppendViaSize(int aSize, int aDrill)
BOARD * GetBoard() const
The main frame for Pcbnew.
void SetBitmap(const wxBitmapBundle &aBmp)
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:546
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:528
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:507
void SetAutoEvalCols(const std::vector< int > &aCols)
Definition: wx_grid.h:104
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:498
void ClearRows()
wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number...
Definition: wx_grid.h:147
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:449
#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...