KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_fp_edit_pad_table.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 The KiCad Developers, see AUTHORS.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
25
26#include <wx/button.h>
27#include <wx/sizer.h>
28#include <wx/dcclient.h>
29#include <wx/stattext.h>
30#include <pcb_shape.h>
31#include <widgets/wx_grid.h>
34#include <base_units.h>
35#include <units_provider.h>
36#include <board.h>
37#include <footprint.h>
39#include <grid_tricks.h>
40#include <pin_numbers.h>
41#include <board_commit.h>
42
43
44// Helper to map shape string to PAD_SHAPE
45static PAD_SHAPE ShapeFromString( const wxString& shape )
46{
47 if( shape == _( "Oval" ) ) return PAD_SHAPE::OVAL;
48 if( shape == _( "Rectangle" ) ) return PAD_SHAPE::RECTANGLE;
49 if( shape == _( "Trapezoid" ) ) return PAD_SHAPE::TRAPEZOID;
50 if( shape == _( "Rounded rectangle" ) ) return PAD_SHAPE::ROUNDRECT;
51 if( shape == _( "Chamfered rectangle" ) ) return PAD_SHAPE::CHAMFERED_RECT;
52 if( shape == _( "Custom shape" ) ) return PAD_SHAPE::CUSTOM;
53
54 return PAD_SHAPE::CIRCLE;
55}
56
57
59 DIALOG_SHIM( (wxWindow*)aParent, wxID_ANY, _( "Pad Table" ), wxDefaultPosition, wxDefaultSize,
60 wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER ),
61 m_frame( aParent ),
62 m_grid( nullptr ),
63 m_footprint( aFootprint ),
65 m_summaryDirty( true )
66{
67 wxBoxSizer* topSizer = new wxBoxSizer( wxVERTICAL );
68
69 wxBoxSizer* bSummarySizer;
70 bSummarySizer = new wxBoxSizer( wxHORIZONTAL );
71
72 m_staticTextPinNumbers = new wxStaticText( this, wxID_ANY, _( "Pad numbers:" ) );
73 m_staticTextPinNumbers->Wrap( -1 );
74 bSummarySizer->Add( m_staticTextPinNumbers, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 5 );
75
76 m_pin_numbers_summary = new wxStaticText( this, wxID_ANY, _( "0" ) );
77 m_pin_numbers_summary->Wrap( -1 );
78 bSummarySizer->Add( m_pin_numbers_summary, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
79
80 bSummarySizer->Add( 0, 0, 1, wxEXPAND, 5 );
81
82 m_staticTextPinCount = new wxStaticText( this, wxID_ANY, _( "Pad count:" ) );
83 m_staticTextPinCount->Wrap( -1 );
84 bSummarySizer->Add( m_staticTextPinCount, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 10 );
85
86 m_pin_count = new wxStaticText( this, wxID_ANY, _( "0" ) );
87 m_pin_count->Wrap( -1 );
88 bSummarySizer->Add( m_pin_count, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
89
90 bSummarySizer->Add( 0, 0, 1, wxEXPAND, 5 );
91
92 m_staticTextDuplicatePins = new wxStaticText( this, wxID_ANY, _("Duplicate pads:" ) );
93 m_staticTextDuplicatePins->Wrap( -1 );
94 bSummarySizer->Add( m_staticTextDuplicatePins, 0, wxALIGN_CENTER_VERTICAL|wxLEFT, 10 );
95
96 m_duplicate_pins = new wxStaticText( this, wxID_ANY, _( "0" ) );
97 m_duplicate_pins->Wrap( -1 );
98 bSummarySizer->Add( m_duplicate_pins, 0, wxRIGHT|wxLEFT|wxALIGN_CENTER_VERTICAL, 5 );
99
100 topSizer->Add( bSummarySizer, 0, wxEXPAND|wxTOP|wxBOTTOM, 5 );
101
102 m_grid = new WX_GRID( this, wxID_ANY );
103 m_grid->CreateGrid( 0, 11 );
104 m_grid->SetColLabelValue( COL_NUMBER, _( "Number" ) );
105 m_grid->SetColLabelValue( COL_TYPE, _( "Type" ) );
106 m_grid->SetColLabelValue( COL_SHAPE, _( "Shape" ) );
107 m_grid->SetColLabelValue( COL_POS_X, _( "X Position" ) );
108 m_grid->SetColLabelValue( COL_POS_Y, _( "Y Position" ) );
109 m_grid->SetColLabelValue( COL_SIZE_X, _( "Size X" ) );
110 m_grid->SetColLabelValue( COL_SIZE_Y, _( "Size Y" ) );
111 m_grid->SetColLabelValue( COL_DRILL_X, _( "Drill X" ) );
112 m_grid->SetColLabelValue( COL_DRILL_Y, _( "Drill Y" ) );
113 m_grid->SetColLabelValue( COL_P2D_LENGTH, _( "Pad->Die Length" ) );
114 m_grid->SetColLabelValue( COL_P2D_DELAY, _( "Pad->Die Delay" ) );
115 m_grid->SetColLabelSize( 24 );
116 m_grid->HideRowLabels();
117 m_grid->EnableEditing( true );
118
119 wxGridCellAttr* attr;
120
121 // Type column editor (attribute)
122 attr = new wxGridCellAttr;
123 wxArrayString typeNames;
124 typeNames.push_back( _( "Through-hole" ) ); // PTH
125 typeNames.push_back( _( "SMD" ) ); // SMD
126 typeNames.push_back( _( "Connector" ) ); // CONN SMD? (use CONN?)
127 typeNames.push_back( _( "NPTH" ) ); // NPTH
128 typeNames.push_back( _( "Aperture" ) ); // inferred copper-less
129 attr->SetEditor( new GRID_CELL_COMBOBOX( typeNames ) );
130 m_grid->SetColAttr( COL_TYPE, attr );
131
132 attr = new wxGridCellAttr;
133 wxArrayString shapeNames;
141 attr->SetEditor( new GRID_CELL_COMBOBOX( shapeNames ) );
142 m_grid->SetColAttr( COL_SHAPE, attr );
143
144 attr = new wxGridCellAttr;
145 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
146 m_grid->SetColAttr( COL_POS_X, attr );
147
148 attr = new wxGridCellAttr;
149 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
150 m_grid->SetColAttr( COL_POS_Y, attr );
151
152 attr = new wxGridCellAttr;
153 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
154 m_grid->SetColAttr( COL_SIZE_X, attr );
155
156 attr = new wxGridCellAttr;
157 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
158 m_grid->SetColAttr( COL_SIZE_Y, attr );
159
160 // Drill X
161 attr = new wxGridCellAttr;
162 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
163 m_grid->SetColAttr( COL_DRILL_X, attr );
164
165 // Drill Y
166 attr = new wxGridCellAttr;
167 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
168 m_grid->SetColAttr( COL_DRILL_Y, attr );
169
170 // Pad->Die Length
171 attr = new wxGridCellAttr;
172 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
173 m_grid->SetColAttr( COL_P2D_LENGTH, attr );
174
175 // Pad->Die Delay
176 attr = new wxGridCellAttr;
177 attr->SetEditor( new GRID_CELL_TEXT_EDITOR() );
178 m_grid->SetColAttr( COL_P2D_DELAY, attr );
179
180 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_POS_X );
181 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_POS_Y );
182 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_SIZE_X );
183 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_SIZE_Y );
184 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_DRILL_X );
185 m_grid->SetUnitsProvider( m_unitsProvider.get(), COL_DRILL_Y );
187
188 // add Cut, Copy, and Paste to wxGrid
189 m_grid->PushEventHandler( new GRID_TRICKS( m_grid ) );
190
191 topSizer->Add( m_grid, 1, wxEXPAND | wxALL, 5 );
192
193 wxStdDialogButtonSizer* buttons = new wxStdDialogButtonSizer();
194 buttons->AddButton( new wxButton( this, wxID_OK ) );
195 buttons->AddButton( new wxButton( this, wxID_CANCEL ) );
196 buttons->Realize();
197 topSizer->Add( buttons, 0, wxALIGN_RIGHT | wxALL, 5 );
198
199 SetSizer( topSizer );
201
203
204 // Bind cell change handlers for real-time updates
205 m_grid->Bind( wxEVT_GRID_CELL_CHANGED, &DIALOG_FP_EDIT_PAD_TABLE::OnCellChanged, this );
206 m_grid->Bind( wxEVT_GRID_SELECT_CELL, &DIALOG_FP_EDIT_PAD_TABLE::OnSelectCell, this );
207 Bind( wxEVT_UPDATE_UI, &DIALOG_FP_EDIT_PAD_TABLE::OnUpdateUI, this );
208
209 // Listen for cancel
210 Bind( wxEVT_BUTTON,
211 [this]( wxCommandEvent& aEvt )
212 {
213 m_cancelled = true;
214 aEvt.Skip();
215 },
216 wxID_CANCEL );
217
219}
220
221
223{
224 if( m_cancelled )
226
227 // destroy GRID_TRICKS before m_grid.
228 m_grid->PopEventHandler( true );
229
230 m_grid->Unbind( wxEVT_GRID_CELL_CHANGED, &DIALOG_FP_EDIT_PAD_TABLE::OnCellChanged, this );
231 m_grid->Unbind( wxEVT_GRID_SELECT_CELL, &DIALOG_FP_EDIT_PAD_TABLE::OnSelectCell, this );
232 Unbind( wxEVT_UPDATE_UI, &DIALOG_FP_EDIT_PAD_TABLE::OnUpdateUI, this );
233}
234
235
237{
238 if( !m_footprint )
239 return false;
240
241 int row = 0;
242
243 for( PAD* pad : m_footprint->Pads() )
244 {
245 m_grid->AppendRows( 1 );
246 m_grid->SetCellValue( row, COL_NUMBER, pad->GetNumber() );
247
248 // Pad attribute to string
249 wxString attrStr;
250
251 switch( pad->GetAttribute() )
252 {
253 case PAD_ATTRIB::PTH: attrStr = _( "Through-hole" ); break;
254 case PAD_ATTRIB::SMD: attrStr = _( "SMD" ); break;
255 case PAD_ATTRIB::CONN: attrStr = _( "Connector" ); break;
256 case PAD_ATTRIB::NPTH: attrStr = _( "NPTH" ); break;
257 default: attrStr = _( "Through-hole" ); break;
258 }
259
260 int size_x = pad->GetSize( PADSTACK::ALL_LAYERS ).x;
261 int size_y = pad->GetSize( PADSTACK::ALL_LAYERS ).y;
262 wxString padShape = pad->ShowPadShape( PADSTACK::ALL_LAYERS );
263
264 pad->Padstack().ForEachUniqueLayer(
265 [&]( PCB_LAYER_ID aLayer )
266 {
267 if( pad->GetSize( aLayer ).x != size_x )
268 size_x = -1;
269
270 if( pad->GetSize( aLayer ).y != size_y )
271 size_y = -1;
272
273 if( pad->ShowPadShape( aLayer ) != padShape )
274 padShape = INDETERMINATE_STATE;
275 } );
276
277 if( pad->IsAperturePad() )
278 attrStr = _( "Aperture" );
279
280 m_grid->SetCellValue( row, COL_TYPE, attrStr );
281 m_grid->SetCellValue( row, COL_SHAPE, padShape );
282 m_grid->SetCellValue( row, COL_POS_X, m_unitsProvider->StringFromValue( pad->GetPosition().x, true ) );
283 m_grid->SetCellValue( row, COL_POS_Y, m_unitsProvider->StringFromValue( pad->GetPosition().y, true ) );
284 m_grid->SetCellValue( row, COL_SIZE_X, size_x >= 0 ? m_unitsProvider->StringFromValue( size_x, true )
286 m_grid->SetCellValue( row, COL_SIZE_Y, size_y >= 0 ? m_unitsProvider->StringFromValue( size_y, true )
288
289 // Drill values (only meaningful for PTH or NPTH). Leave empty otherwise.
290 if( pad->GetAttribute() == PAD_ATTRIB::PTH || pad->GetAttribute() == PAD_ATTRIB::NPTH )
291 {
292 VECTOR2I drill = pad->GetDrillSize();
293
294 if( drill.x > 0 )
295 m_grid->SetCellValue( row, COL_DRILL_X, m_unitsProvider->StringFromValue( drill.x, true ) );
296
297 if( drill.y > 0 )
298 m_grid->SetCellValue( row, COL_DRILL_Y, m_unitsProvider->StringFromValue( drill.y, true ) );
299 }
300 else
301 {
302 // For non-PTH pads, drill columns are not applicable.
303 m_grid->SetReadOnly( row, COL_DRILL_X, true );
304 m_grid->SetReadOnly( row, COL_DRILL_Y, true );
305 }
306
307 // Pad to die metrics
308 if( pad->GetPadToDieLength() )
309 m_grid->SetCellValue( row, COL_P2D_LENGTH, m_unitsProvider->StringFromValue( pad->GetPadToDieLength(), true ) );
310
311 if( pad->GetPadToDieDelay() )
312 m_grid->SetCellValue( row, COL_P2D_DELAY, wxString::Format( "%d", pad->GetPadToDieDelay() ) );
313
314 row++;
315 }
316
317 // Auto size the data columns first to get reasonable initial widths
318 m_grid->AutoSizeColumns();
319
320 // Ensure the Shape column (index 1) is wide enough for the longest translated
321 // shape text plus the dropdown arrow / padding. We compute a max text width
322 // using a device context and add a platform neutral padding.
323 {
324 wxClientDC dc( m_grid );
325 dc.SetFont( m_grid->GetFont() );
326
327 wxArrayString shapeNames;
335
336 int maxWidth = 0;
337
338 for( const wxString& str : shapeNames )
339 {
340 int w, h;
341 dc.GetTextExtent( str, &w, &h );
342 maxWidth = std::max( maxWidth, w );
343 }
344
345 // Add padding for internal cell margins + dropdown control.
346 int padding = FromDIP( 30 ); // heuristic: 2*margin + arrow button
347 m_grid->SetColSize( COL_SHAPE, maxWidth + padding );
348 }
349
350 // Record initial proportions for proportional resizing later.
352 Bind( wxEVT_SIZE, &DIALOG_FP_EDIT_PAD_TABLE::OnSize, this );
353
354 // Run an initial proportional resize using current client size so columns
355 // respect proportions immediately.
356 wxSizeEvent sizeEvt( GetSize(), GetId() );
357 CallAfter(
358 [this, sizeEvt]
359 {
360 wxSizeEvent evt( sizeEvt );
361 this->OnSize( evt );
362 } );
363
364 // If pads exist, select the first row to show initial highlight
365 if( m_grid->GetNumberRows() > 0 )
366 {
367 m_grid->SetGridCursor( 0, 0 );
368 // Construct event with required parameters (id, type, obj, row, col,...)
369 wxGridEvent ev( m_grid->GetId(), wxEVT_GRID_SELECT_CELL, m_grid, 0, 0, -1, -1, true );
370 OnSelectCell( ev );
371 }
372
373 return true;
374}
375
376
378{
379 m_originalPads.clear();
380
381 if( !m_footprint )
382 return;
383
384 for( PAD* pad : m_footprint->Pads() )
385 {
386 PAD_SNAPSHOT snap( pad );
387 snap.number = pad->GetNumber();
388 snap.position = pad->GetPosition();
389 snap.padstack = pad->Padstack();
390 snap.attribute = pad->GetAttribute();
391 snap.padToDieLength= pad->GetPadToDieLength();
392 snap.padToDieDelay = pad->GetPadToDieDelay();
393 m_originalPads.push_back( snap );
394 }
395}
396
397
399{
400 if( !m_footprint )
401 return;
402
403 size_t idx = 0;
404 PCB_BASE_FRAME* base = dynamic_cast<PCB_BASE_FRAME*>( GetParent() );
405 PCB_DRAW_PANEL_GAL* canvas = base ? base->GetCanvas() : nullptr;
406
407 for( PAD* pad : m_footprint->Pads() )
408 {
409 if( idx >= m_originalPads.size() )
410 break;
411
412 const PAD_SNAPSHOT& snap = m_originalPads[idx++];
413 pad->SetNumber( snap.number );
414 pad->SetPosition( snap.position );
415 pad->SetPadstack( snap.padstack );
416 pad->SetAttribute( snap.attribute );
417 pad->SetPadToDieLength( snap.padToDieLength );
418 pad->SetPadToDieDelay( snap.padToDieDelay );
419 pad->ClearBrightened();
420
421 if( canvas )
422 canvas->GetView()->Update( pad, KIGFX::REPAINT );
423 }
424
425 if( canvas )
426 {
428 canvas->ForceRefresh();
429 }
430
431 m_summaryDirty = true;
432}
433
434
436{
437 if( !m_grid->CommitPendingChanges() )
438 return false;
439
440 if( !m_footprint )
441 return true;
442
444 BOARD_COMMIT commit( m_frame );
445
446 int row = 0;
447
448 for( PAD* pad : m_footprint->Pads() )
449 {
450 commit.Modify( pad );
451 pad->SetNumber( m_grid->GetCellValue( row, COL_NUMBER ) );
452
453 wxString typeStr = m_grid->GetCellValue( row, COL_TYPE );
454
455 if( typeStr == _( "Through-hole" ) )
456 pad->SetAttribute( PAD_ATTRIB::PTH );
457 else if( typeStr == _( "SMD" ) )
458 pad->SetAttribute( PAD_ATTRIB::SMD );
459 else if( typeStr == _( "Connector" ) )
460 pad->SetAttribute( PAD_ATTRIB::CONN );
461 else if( typeStr == _( "NPTH" ) )
462 pad->SetAttribute( PAD_ATTRIB::NPTH );
463 // Aperture derived by copper-less layers; do not overwrite attribute here.
464
465 wxString shape = m_grid->GetCellValue( row, COL_SHAPE );
466
467 if( shape != INDETERMINATE_STATE )
468 {
469 PAD_SHAPE newShape = ShapeFromString( shape );
470
471 pad->Padstack().ForEachUniqueLayer(
472 [&]( PCB_LAYER_ID aLayer )
473 {
474 pad->SetShape( aLayer, newShape );
475 } );
476 }
477
478 VECTOR2I pos;
479 pos.x = m_grid->GetUnitValue( row, COL_POS_X );
480 pos.y = m_grid->GetUnitValue( row, COL_POS_Y );
481 pad->SetPosition( pos );
482
483 wxString size_x_value = m_grid->GetCellValue( row, COL_SIZE_X );
484
485 if( size_x_value != INDETERMINATE_STATE )
486 {
487 int size_x = m_grid->GetUnitValue( row, COL_SIZE_X );
488
489 pad->Padstack().ForEachUniqueLayer(
490 [&]( PCB_LAYER_ID aLayer )
491 {
492 VECTOR2I size( size_x, pad->GetSize( aLayer ).y );
493 pad->SetSize( aLayer, size );
494 } );
495 }
496
497 wxString size_y_value = m_grid->GetCellValue( row, COL_SIZE_Y );
498
499 if( size_y_value != INDETERMINATE_STATE )
500 {
501 int size_y = m_grid->GetUnitValue( row, COL_SIZE_Y );
502
503 pad->Padstack().ForEachUniqueLayer(
504 [&]( PCB_LAYER_ID aLayer )
505 {
506 VECTOR2I size( pad->GetSize( aLayer ).x, size_y );
507 pad->SetSize( aLayer, size );
508 } );
509 }
510
511 // Drill sizes (only if attribute allows)
512 if( pad->GetAttribute() == PAD_ATTRIB::PTH || pad->GetAttribute() == PAD_ATTRIB::NPTH )
513 {
514 int drill_x = m_grid->GetUnitValue( row, COL_DRILL_X );
515 int drill_y = m_grid->GetUnitValue( row, COL_DRILL_Y );
516
517 if( drill_x > 0 || drill_y > 0 )
518 {
519 if( drill_x <= 0 )
520 drill_x = drill_y;
521
522 if( drill_y <= 0 )
523 drill_y = drill_x;
524
525 pad->SetDrillSize( { drill_x, drill_y } );
526 }
527 }
528
529 // Pad->Die
530 wxString delayStr = m_grid->GetCellValue( row, COL_P2D_DELAY );
531 wxString lenStr = m_grid->GetCellValue( row, COL_P2D_LENGTH );
532
533 if( !lenStr.IsEmpty() )
534 pad->SetPadToDieLength( m_grid->GetUnitValue( row, COL_P2D_LENGTH ) );
535 else
536 pad->SetPadToDieLength( 0 );
537
538 if( !delayStr.IsEmpty() )
539 {
540 long delayVal;
541
542 if( delayStr.ToLong( &delayVal ) )
543 pad->SetPadToDieDelay( (int) delayVal );
544 else
545 pad->SetPadToDieDelay( 0 );
546 }
547 else
548 pad->SetPadToDieDelay( 0 );
549
550 row++;
551 }
552
553 commit.Push( _( "Edit Pads" ) );
554 m_frame->Refresh();
555
556 return true;
557}
558
559
561{
562 m_colProportions.clear();
563 m_minColWidths.clear();
564
565 if( !m_grid )
566 return;
567
568 // Only consider the actual data columns (all of them since row labels are hidden)
569 int cols = m_grid->GetNumberCols();
570 int total = 0;
571 std::vector<int> widths;
572 widths.reserve( cols );
573
574 for( int c = 0; c < cols; ++c )
575 {
576 int w = m_grid->GetColSize( c );
577 widths.push_back( w );
578 total += w;
579 }
580
581 if( total <= 0 )
582 return;
583
584 for( int w : widths )
585 {
586 m_colProportions.push_back( (double) w / (double) total );
587 m_minColWidths.push_back( w );
588 }
589}
590
591
592void DIALOG_FP_EDIT_PAD_TABLE::OnSize( wxSizeEvent& aEvent )
593{
594 if( m_colProportions.empty() )
595 {
596 aEvent.Skip();
597 return;
598 }
599
600 // Compute available total width for columns and resize keeping proportions.
601 int cols = m_grid->GetNumberCols();
602 int available = 0;
603
604 for( int c = 0; c < cols; ++c )
605 available += m_grid->GetColSize( c );
606
607 // Use client size of grid minus scrollbar estimate to better distribute.
608 int clientW = m_grid->GetClientSize().x;
609
610 if( clientW > 0 )
611 available = clientW; // prefer actual client width
612
613 int used = 0;
614
615 for( int c = 0; c < cols; ++c )
616 {
617 int target = (int) std::round( m_colProportions[c] * available );
618 target = std::max( target, m_minColWidths[c] );
619
620 // Defer last column to absorb rounding diff.
621 if( c == cols - 1 )
622 target = std::max( available - used, m_minColWidths[c] );
623
624 m_grid->SetColSize( c, target );
625 used += target;
626 }
627
628 aEvent.Skip();
629}
630
631
632void DIALOG_FP_EDIT_PAD_TABLE::OnCharHook( wxKeyEvent& aEvent )
633{
634 if( m_grid->IsCellEditControlShown() && m_grid->GetGridCursorCol() == COL_NUMBER )
635 m_summaryDirty = true;
636
637 DIALOG_SHIM::OnCharHook( aEvent );
638}
639
640
642{
643 int row = aEvent.GetRow();
644 int col = aEvent.GetCol();
645
646 if( !m_footprint )
647 return;
648
649 // row -> pad mapping is current order of Pads() iteration; rebuild each time (pads count small)
650 int idx = 0;
651 PAD* target = nullptr;
652
653 for( PAD* pad : m_footprint->Pads() )
654 {
655 if( idx == row )
656 {
657 target = pad;
658 break;
659 }
660
661 ++idx;
662 }
663
664 if( !target )
665 return;
666
667 bool needCanvasRefresh = false;
668
669 switch( col )
670 {
671 case COL_NUMBER:
672 target->SetNumber( m_grid->GetCellValue( row, col ) );
673 needCanvasRefresh = true;
674 m_summaryDirty = true;
675 break;
676
677 case COL_TYPE:
678 {
679 wxString typeStr = m_grid->GetCellValue( row, col );
680 PAD_ATTRIB newAttr = target->GetAttribute();
681
682 if( typeStr == _( "Through-hole" ) )
683 newAttr = PAD_ATTRIB::PTH;
684 else if( typeStr == _( "SMD" ) )
685 newAttr = PAD_ATTRIB::SMD;
686 else if( typeStr == _( "Connector" ) )
687 newAttr = PAD_ATTRIB::CONN;
688 else if( typeStr == _( "NPTH" ) )
689 newAttr = PAD_ATTRIB::NPTH;
690
691 if( newAttr != target->GetAttribute() )
692 {
693 target->SetAttribute( newAttr );
694
695 // Toggle drill columns read-only state dynamically.
696 bool drillsEditable = ( newAttr == PAD_ATTRIB::PTH || newAttr == PAD_ATTRIB::NPTH );
697 m_grid->SetReadOnly( row, COL_DRILL_X, !drillsEditable );
698 m_grid->SetReadOnly( row, COL_DRILL_Y, !drillsEditable );
699 needCanvasRefresh = true;
700 }
701 break;
702 }
703
704 case COL_SHAPE:
705 target->SetShape( PADSTACK::ALL_LAYERS, ShapeFromString( m_grid->GetCellValue( row, col ) ) );
706 needCanvasRefresh = true;
707 break;
708
709 case COL_POS_X:
710 case COL_POS_Y:
711 {
712 VECTOR2I pos = target->GetPosition();
713
714 if( col == COL_POS_X )
715 pos.x = m_grid->GetUnitValue( row, col );
716 else
717 pos.y = m_grid->GetUnitValue( row, col );
718
719 target->SetPosition( pos );
720 needCanvasRefresh = true;
721 break;
722 }
723
724 case COL_SIZE_X:
725 case COL_SIZE_Y:
726 {
727 VECTOR2I size = target->GetSize( PADSTACK::ALL_LAYERS );
728
729 if( col == COL_SIZE_X )
730 size.x = m_grid->GetUnitValue( row, col );
731 else
732 size.y = m_grid->GetUnitValue( row, col );
733
734 target->SetSize( PADSTACK::ALL_LAYERS, size );
735 needCanvasRefresh = true;
736 break;
737 }
738
739 case COL_DRILL_X:
740 case COL_DRILL_Y:
741 {
742 if( target->GetAttribute() == PAD_ATTRIB::PTH || target->GetAttribute() == PAD_ATTRIB::NPTH )
743 {
744 int dx = m_grid->GetUnitValue( row, COL_DRILL_X );
745 int dy = m_grid->GetUnitValue( row, COL_DRILL_Y );
746 if( dx > 0 || dy > 0 )
747 {
748 if( dx <= 0 ) dx = dy;
749 if( dy <= 0 ) dy = dx;
750 target->SetDrillSize( { dx, dy } );
751 needCanvasRefresh = true;
752 }
753 }
754
755 break;
756 }
757
758 case COL_P2D_LENGTH:
759 if( !m_grid->GetCellValue( row, col ).IsEmpty() )
760 target->SetPadToDieLength( m_grid->GetUnitValue( row, col ) );
761
762 break;
763
764 case COL_P2D_DELAY:
765 {
766 wxString d = m_grid->GetCellValue( row, col );
767 long val;
768
769 if( d.ToLong( &val ) )
770 target->SetPadToDieDelay( (int) val );
771
772 break;
773 }
774
775 default:
776 break;
777 }
778
779 // Request redraw (simple approach)
780 target->SetDirty();
781
782 if( needCanvasRefresh )
783 {
784 if( PCB_BASE_FRAME* base = dynamic_cast<PCB_BASE_FRAME*>( GetParent() ) )
785 base->GetCanvas()->ForceRefresh();
786 }
787}
788
789
790void DIALOG_FP_EDIT_PAD_TABLE::OnSelectCell( wxGridEvent& aEvent )
791{
792 int row = aEvent.GetRow();
793
794 if( !m_footprint )
795 return;
796
797 PCB_BASE_FRAME* base = dynamic_cast<PCB_BASE_FRAME*>( GetParent() );
798 PCB_DRAW_PANEL_GAL* canvas = base ? base->GetCanvas() : nullptr;
799
800 // Clear existing pad selections
801 for( PAD* pad : m_footprint->Pads() )
802 {
803 if( pad->IsBrightened() )
804 {
805 pad->ClearBrightened();
806
807 if( canvas )
808 canvas->GetView()->Update( pad, KIGFX::REPAINT );
809 }
810 }
811
812 int idx = 0;
813
814 for( PAD* pad : m_footprint->Pads() )
815 {
816 if( idx == row )
817 {
818 pad->SetBrightened();
819
820 if( canvas )
821 {
822 canvas->GetView()->Update( pad, KIGFX::REPAINT );
823 canvas->ForceRefresh();
824 }
825
826 break;
827 }
828
829 ++idx;
830 }
831}
832
833
834void DIALOG_FP_EDIT_PAD_TABLE::OnUpdateUI( wxUpdateUIEvent& aEvent )
835{
836 if( m_summaryDirty )
837 {
838 if( m_grid->IsCellEditControlShown() && m_grid->GetGridCursorCol() == COL_NUMBER )
839 {
840 int row = m_grid->GetGridCursorRow();
841 int col = m_grid->GetGridCursorCol();
842 int idx = 0;
843 PAD* target = nullptr;
844
845 for( PAD* pad : m_footprint->Pads() )
846 {
847 if( idx == row )
848 {
849 target = pad;
850 break;
851 }
852
853 ++idx;
854 }
855
856 if( target )
857 target->SetNumber( m_grid->GetCellEditor( row, col )->GetValue() );
858 }
859
861 m_summaryDirty = false;
862 }
863}
864
865
867{
868 PIN_NUMBERS pinNumbers;
869
870 for( PAD* pad : m_footprint->Pads() )
871 {
872 if( pad->GetNumber().Length() )
873 pinNumbers.insert( pad->GetNumber() );
874 }
875
876 m_pin_numbers_summary->SetLabel( pinNumbers.GetSummary() );
877 m_pin_count->SetLabel( wxString::Format( wxT( "%u" ), (unsigned) m_footprint->Pads().size() ) );
878 m_duplicate_pins->SetLabel( pinNumbers.GetDuplicates() );
879
880 Layout();
881}
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:112
virtual void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
Definition commit.h:106
DIALOG_FP_EDIT_PAD_TABLE(PCB_BASE_FRAME *aParent, FOOTPRINT *aFootprint)
void OnCharHook(wxKeyEvent &aEvent) override
void OnUpdateUI(wxUpdateUIEvent &aEvent)
std::vector< PAD_SNAPSHOT > m_originalPads
void OnSize(wxSizeEvent &aEvent)
void OnCellChanged(wxGridEvent &aEvent)
std::vector< double > m_colProportions
std::unique_ptr< UNITS_PROVIDER > m_unitsProvider
void OnSelectCell(wxGridEvent &aEvent)
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_SHIM(wxWindow *aParent, wxWindowID id, const wxString &title, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxDEFAULT_FRAME_STYLE|wxRESIZE_BORDER, const wxString &name=wxDialogNameStr)
virtual void OnCharHook(wxKeyEvent &aEvt)
EDA_UNITS GetUserUnits() const
void ForceRefresh()
Force a redraw.
This class works around a bug in wxGrid where the first keystroke doesn't get sent through the valida...
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition grid_tricks.h:61
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const override
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition pcb_view.cpp:91
void MarkTargetDirty(int aTarget)
Set or clear target 'dirty' flag.
Definition view.h:639
static constexpr PCB_LAYER_ID ALL_LAYERS
! Temporary layer identifier to identify code that is not padstack-aware
Definition padstack.h:177
Definition pad.h:55
void SetAttribute(PAD_ATTRIB aAttribute)
Definition pad.cpp:1318
static wxString ShowPadShape(PAD_SHAPE aShape)
Definition pad.cpp:2055
PAD_ATTRIB GetAttribute() const
Definition pad.h:558
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition pad.h:187
VECTOR2I GetPosition() const override
Definition pad.h:209
void SetDirty()
Definition pad.h:547
void SetPadToDieDelay(int aDelay)
Definition pad.h:573
void SetNumber(const wxString &aNumber)
Set the pad number (note that it can be alphanumeric, such as the array reference "AA12").
Definition pad.h:136
void SetPosition(const VECTOR2I &aPos) override
Definition pad.h:203
void SetDrillSize(const VECTOR2I &aSize)
Definition pad.h:311
void SetSize(PCB_LAYER_ID aLayer, const VECTOR2I &aSize)
Definition pad.h:259
void SetPadToDieLength(int aLength)
Definition pad.h:570
const VECTOR2I & GetSize(PCB_LAYER_ID aLayer) const
Definition pad.h:264
Base PCB main window class for Pcbnew, Gerbview, and CvPcb footprint viewer.
PCB_DRAW_PANEL_GAL * GetCanvas() const override
Return a pointer to GAL-based canvas of given EDA draw frame.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the #VIEW instance used in the panel.
wxString GetDuplicates() const
Gets a formatted string of all the pins that have duplicate numbers.
void insert(value_type const &v)
Definition pin_numbers.h:62
wxString GetSummary() const
static PAD_SHAPE ShapeFromString(const wxString &shape)
#define _(s)
static std::map< int, wxString > shapeNames
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:60
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:58
@ TARGET_OVERLAY
Items that may change while the view stays the same (noncached)
Definition definitions.h:39
STL namespace.
PAD_ATTRIB
The set of pad shapes, used with PAD::{Set,Get}Attribute().
Definition padstack.h:97
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:103
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:99
@ PTH
Plated through hole pad.
Definition padstack.h:98
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Definition padstack.h:100
PAD_SHAPE
The set of pad shapes, used with PAD::{Set,Get}Shape()
Definition padstack.h:52
@ CHAMFERED_RECT
Definition padstack.h:60
@ ROUNDRECT
Definition padstack.h:57
@ TRAPEZOID
Definition padstack.h:56
@ RECTANGLE
Definition padstack.h:54
#define INDETERMINATE_STATE
Used for holding indeterminate values, such as with multiple selections holding different values or c...
Definition ui_common.h:46
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:695