KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pad_tool.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, see <https://www.gnu.org/licenses/>.
18 */
19
20
21#include "pad_tool.h"
22
23#include <algorithm>
24#include <memory>
25#include <optional>
26#include <unordered_map>
27
28#include <kiid.h>
29#include <pcb_painter.h>
30#include <kiplatform/ui.h>
31#include <macros.h>
33#include <view/view_controls.h>
34#include <tool/tool_manager.h>
37#include <board_item.h>
38#include <collectors.h>
39#include <footprint.h>
40#include <pcb_shape.h>
41#include <pad.h>
42#include <pad_utils.h>
43#include <pcbnew_settings.h>
44#include <string_utils.h>
45#include <board_commit.h>
48#include <tools/pcb_actions.h>
52#include <tools/edit_tool.h>
54#include <widgets/wx_infobar.h>
55
56
58
59
61{
62public:
74
76
91 PAD GetMasterPad( TYPE aType, const FOOTPRINT* aFootprint, const PAD* aSelectedPad ) const
92 {
93 std::vector<const PAD*> fpPads;
94
95 if( aFootprint )
96 {
97 fpPads.assign( aFootprint->Pads().begin(), aFootprint->Pads().end() );
98
99 const auto reverseNumberSorter =
100 []( const PAD* a, const PAD* b )
101 {
102 return StrNumCmp( a->GetNumber(), b->GetNumber() ) > 0;
103 };
104
105 // Sort the pads in reverse number order (we want to avoid choosing pin 1, usually)
106 std::sort( fpPads.begin(), fpPads.end(), reverseNumberSorter );
107 }
108
109 // Resolve the most recent pad type if the requested type is AUTO.
110 // Note that the selection-copy logic is only used for AUTO. If the user uses,
111 // say, THT explicitly, then we don't try to copy the selection.
112 if( aType == TYPE::AUTO )
113 {
114 aType = resolveAutoType( fpPads, aSelectedPad );
115
116 // If the type came from the selected pad, that pad is the template as well.
117 if( aSelectedPad && TypeFromPad( *aSelectedPad ) == aType )
118 return *aSelectedPad;
119 }
120
121 // See if the most recently created pad of the requested type can still be found
122 if( auto lastRealPadIt = m_lastRealPadsForType.find( aType ); lastRealPadIt != m_lastRealPadsForType.end() )
123 {
124 for( const PAD* pad : fpPads )
125 {
126 if( pad->m_Uuid == lastRealPadIt->second )
127 {
128 // Check it still has this type
129 std::optional<TYPE> padType = TypeFromPad( *pad );
130 if( !padType || *padType != aType )
131 break;
132
133 return *pad;
134 }
135 }
136 }
137
138 // If that doesn't work, look in the current footprint for ideas
139 if( aFootprint )
140 {
141 for( const PAD* pad : fpPads )
142 {
143 std::optional<TYPE> padType = TypeFromPad( *pad );
144
145 // If this pad is the one we're looking for
146 if( padType && *padType == aType )
147 {
148 return *pad;
149 }
150 }
151 }
152
153 // If we still don't have a master pad, fall back to a constructed default
154 return *MakeDefaultPad( aType );
155 }
156
160 std::unique_ptr<PAD> MakeDefaultPad( PAD_MASTER_PROVIDER::TYPE aMasterType ) const
161 {
162 std::unique_ptr<PAD> pad = std::make_unique<PAD>( nullptr );
163
164 pad->SetPadstackMode( PADSTACK::MODE::NORMAL );
165 pad->SetThermalSpokeAngle( ANGLE_90 );
166
167 switch( aMasterType )
168 {
169 case PAD_MASTER_PROVIDER::TYPE::THT:
170 {
171 pad->SetAttribute( PAD_ATTRIB::PTH );
172 pad->SetLayerSet( PAD::PTHMask() );
174
178 } );
179
180 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
181 pad->SetDrillSize( VECTOR2D{
184 } );
185 break;
186 }
187 case PAD_MASTER_PROVIDER::TYPE::SMD:
188 {
189 pad->SetAttribute( PAD_ATTRIB::SMD );
190 pad->SetLayerSet( PAD::SMDMask() );
191
193
197 } );
198 // No drill for SMD pads
199 break;
200 }
201 case PAD_MASTER_PROVIDER::TYPE::NPTH:
202 {
203 pad->SetAttribute( PAD_ATTRIB::NPTH );
204 pad->SetLayerSet( PAD::UnplatedHoleMask() );
206
207 const VECTOR2D size = VECTOR2D{
210 };
211 pad->SetSize( PADSTACK::ALL_LAYERS, size );
212 pad->SetDrillShape( PAD_DRILL_SHAPE::CIRCLE );
213 pad->SetDrillSize( size );
214
215 break;
216 }
217 case PAD_MASTER_PROVIDER::TYPE::PASTE:
218 case PAD_MASTER_PROVIDER::TYPE::MASK:
219 {
220 pad->SetAttribute( PAD_ATTRIB::SMD );
221
222 if( aMasterType == PAD_MASTER_PROVIDER::TYPE::PASTE )
223 pad->SetLayerSet( PAD::ApertureMask() );
224 else
225 pad->SetLayerSet( LSET{ F_Mask } );
226
231 } );
232 break;
233 }
234 case PAD_MASTER_PROVIDER::TYPE::CONNECTOR:
235 {
236 pad->SetAttribute( PAD_ATTRIB::CONN );
237 pad->SetLayerSet( PAD::ConnSMDMask() );
238
243 } );
244 break;
245 }
246 case PAD_MASTER_PROVIDER::TYPE::NON_COMPONENT:
247 {
248 pad->SetAttribute( PAD_ATTRIB::NON_COMPONENT );
249 pad->SetLayerSet( { F_Cu } );
251
252 const VECTOR2D size = VECTOR2D{
255 };
256 pad->SetSize( PADSTACK::ALL_LAYERS, size );
257 break;
258 }
259 // No Default: handle every case explicitly
260 case PAD_MASTER_PROVIDER::TYPE::AUTO:
261 {
262 wxFAIL_MSG( "AUTO pad type should not be used for default pad creation" );
263 break;
264 }
265 }
266
267 // Set an IPC-standard rouding radius when useful
268 if( pad->GetShape( PADSTACK::ALL_LAYERS ) == PAD_SHAPE::ROUNDRECT )
269 {
271 pad->SetRoundRectRadiusRatio( PADSTACK::ALL_LAYERS, newRadius );
272 }
273
274 return pad;
275 }
276
282 void RecordNewMasterPad( const PAD& aPlacedPad )
283 {
284 std::optional<TYPE> padType = TypeFromPad( aPlacedPad );
285
286 // Don't update the MRU records if the pad type could not be determined.
287 if( !padType )
288 return;
289
290 m_lastType = *padType;
291 m_lastRealPadsForType[*padType] = aPlacedPad.m_Uuid;
292 }
293
294 static TYPE TypeFromAction( const TOOL_EVENT& aEvent )
295 {
296 if( aEvent.IsAction( &PCB_ACTIONS::placeThtPad ) )
297 return TYPE::THT;
298 if( aEvent.IsAction( &PCB_ACTIONS::placeSmdPad ) )
299 return TYPE::SMD;
300 if( aEvent.IsAction( &PCB_ACTIONS::placeNpthPad ) )
301 return TYPE::NPTH;
303 return TYPE::PASTE;
304
305 return TYPE::AUTO;
306 }
307
313 static std::optional<TYPE> TypeFromPad( const PAD& aPad )
314 {
315 if( aPad.GetAttribute() == PAD_ATTRIB::PTH )
316 return TYPE::THT;
317 if( aPad.GetAttribute() == PAD_ATTRIB::SMD )
318 {
319 if( aPad.IsAperturePad() )
320 {
321 if( ( aPad.GetLayerSet() & LSET{ F_Paste, B_Paste } ).any() )
322 return TYPE::PASTE;
323
324 if( ( aPad.GetLayerSet() & LSET{ F_Mask, B_Mask } ).any() )
325 return TYPE::MASK;
326
327 // Weird case: an aperture pad with no paste or mask layers
328 return std::nullopt;
329 }
330
331 return TYPE::SMD;
332 }
333 if( aPad.GetAttribute() == PAD_ATTRIB::CONN )
334 return TYPE::CONNECTOR;
336 return TYPE::NON_COMPONENT;
337 if( aPad.GetAttribute() == PAD_ATTRIB::NPTH )
338 return TYPE::NPTH;
339
340 return std::nullopt;
341 }
342
343private:
354 TYPE resolveAutoType( const std::vector<const PAD*>& aFpPads, const PAD* aSelectedPad ) const
355 {
356 if( aSelectedPad )
357 {
358 std::optional<TYPE> selectedType = TypeFromPad( *aSelectedPad );
359 if( selectedType )
360 return *selectedType;
361 }
362
363 if( m_lastType != TYPE::AUTO )
364 return m_lastType;
365
366 for( const PAD* pad : aFpPads )
367 {
368 if( std::optional<TYPE> padType = TypeFromPad( *pad ) )
369 return *padType;
370 }
371
372 return TYPE::THT;
373 }
374
375 // Persistent store of the last real pad's ID for each type.
376 // Note that the pad with this UUID may not exist in the current footprint,
377 // or may no longer have the recorded type.
378 std::unordered_map<TYPE, KIID> m_lastRealPadsForType;
379
381 TYPE m_lastType = PAD_MASTER_PROVIDER::TYPE::AUTO;
382};
383
384
386 PCB_TOOL_BASE( "pcbnew.PadTool" ),
390 m_bufferPad( std::make_unique<PAD>( nullptr ) )
391{
392 // Seed the paste buffer with a sensible default at startup.
393 m_bufferPad->ImportSettingsFrom( *m_masterPadProvider->MakeDefaultPad( PAD_MASTER_PROVIDER::TYPE::THT ) );
394}
395
396
400
401
403{
404 m_masterPadProvider->RecordNewMasterPad( aPad );
405}
406
407
409{
410 if( aReason == MODEL_RELOAD )
411 m_lastPadNumber = wxT( "1" );
412
413 if( board() && board()->ResolveItem( m_editPad ) == DELETED_BOARD_ITEM::GetInstance() )
414 {
415 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
416
418 {
420 frame()->SetDisplayOptions( opts );
421 }
422
423 frame()->GetInfoBar()->Dismiss();
424
426 }
427}
428
429
431{
432 static const std::vector<KICAD_T> padTypes = { PCB_PAD_T };
433
434 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
435
436 if( selTool )
437 {
438 // Add context menu entries that are displayed when selection tool is active
439 CONDITIONAL_MENU& menu = selTool->GetToolMenu().GetMenu();
440
444
445 auto explodeCondition =
446 [this]( const SELECTION& aSel )
447 {
448 return m_editPad == niluuid && aSel.Size() == 1 && aSel[0]->Type() == PCB_PAD_T;
449 };
450
451 auto recombineCondition =
452 [this]( const SELECTION& aSel )
453 {
454 return m_editPad != niluuid;
455 };
456
457 menu.AddSeparator( 400 );
458
460 {
463 menu.AddItem( PCB_ACTIONS::recombinePad, recombineCondition, 400 );
464 menu.AddItem( PCB_ACTIONS::explodePad, explodeCondition, 400 );
465 }
466
467 menu.AddItem( PCB_ACTIONS::copyPadSettings, singlePadSel, 400 );
468 menu.AddItem( PCB_ACTIONS::applyPadSettings, padSel, 400 );
469 menu.AddItem( PCB_ACTIONS::pushPadSettings, singlePadSel, 400 );
470 }
471
472 auto& ctxMenu = m_menu->GetMenu();
473
474 // cancel current tool goes in main context menu at the top if present
476 ctxMenu.AddSeparator( 1 );
477
484
485 // Finally, add the standard zoom/grid items
486 getEditFrame<PCB_BASE_FRAME>()->AddStandardSubMenus( *m_menu.get() );
487
488 return true;
489}
490
491
493{
494 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
495 const PCB_SELECTION& selection = selTool->GetSelection();
496
497 BOARD_COMMIT commit( frame() );
498
499 // for every selected pad, paste global settings
500 for( EDA_ITEM* item : selection )
501 {
502 if( item->Type() == PCB_PAD_T )
503 {
504 commit.Modify( item );
505 static_cast<PAD&>( *item ).ImportSettingsFrom( *m_bufferPad );
506 }
507 }
508
509 commit.Push( _( "Paste Pad Properties" ) );
510
512 frame()->Refresh();
513
514 return 0;
515}
516
517
519{
520 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
521 const PCB_SELECTION& selection = selTool->GetSelection();
522
523 // can only copy from a single pad
524 if( selection.Size() == 1 )
525 {
526 EDA_ITEM* item = selection[0];
527
528 if( item->Type() == PCB_PAD_T )
529 {
530 const PAD& selPad = static_cast<const PAD&>( *item );
531
532 // Store the settings in the buffer pad for paste
533 m_bufferPad->ImportSettingsFrom( selPad );
534
535 // And push into the master pad provider for future use
536 m_masterPadProvider->RecordNewMasterPad( selPad );
537 }
538 }
539
540 return 0;
541}
542
543
548static bool padSizesMatch( const PAD& aPad1, const PAD& aPad2 )
549{
550 LSET relevantLayers = aPad1.Padstack().RelevantShapeLayers( aPad2.Padstack() );
551
552 for( PCB_LAYER_ID aLayer : relevantLayers )
553 {
554 if( aPad1.GetSize( aLayer ) != aPad2.GetSize( aLayer ) )
555 return false;
556 }
557
558 return true;
559}
560
561
562static void doPushPadProperties( BOARD& board, const PAD& aSrcPad, BOARD_COMMIT& commit, bool aSameFootprints,
563 bool aPadShapeFilter, bool aPadSizeFilter, bool aPadOrientFilter, bool aPadLayerFilter,
564 bool aPadTypeFilter )
565{
566 const FOOTPRINT* refFootprint = aSrcPad.GetParentFootprint();
567
568 EDA_ANGLE srcPadAngle = aSrcPad.GetOrientation() - refFootprint->GetOrientation();
569
570 for( FOOTPRINT* footprint : board.Footprints() )
571 {
572 if( !aSameFootprints && ( footprint != refFootprint ) )
573 continue;
574
575 if( footprint->GetFPID() != refFootprint->GetFPID() )
576 continue;
577
578 for( PAD* pad : footprint->Pads() )
579 {
580 if( aPadShapeFilter )
581 {
582 bool shapesMatch = true;
583
584 // Compare in both directions to catch all potentialy unique layer defintions
585 pad->Padstack().ForEachUniqueLayer(
586 [&]( PCB_LAYER_ID aLayer )
587 {
588 if( pad->GetShape( aLayer ) != aSrcPad.GetShape( aLayer ) )
589 shapesMatch = false;
590 } );
591
593 [&]( PCB_LAYER_ID aLayer )
594 {
595 if( aSrcPad.GetShape( aLayer ) != pad->GetShape( aLayer ) )
596 shapesMatch = false;
597 } );
598
599 if( !shapesMatch )
600 continue;
601 }
602
603 EDA_ANGLE padAngle = pad->GetOrientation() - footprint->GetOrientation();
604
605 if( aPadSizeFilter && ( !padSizesMatch( *pad, aSrcPad ) ) )
606 continue;
607
608 if( aPadOrientFilter && ( padAngle != srcPadAngle ) )
609 continue;
610
611 if( aPadLayerFilter && ( pad->GetLayerSet() != aSrcPad.GetLayerSet() ) )
612 continue;
613
614 if( aPadTypeFilter && ( pad->GetAttribute() != aSrcPad.GetAttribute() ) )
615 continue;
616
617 // Special-case for aperture pads
618 if( aPadTypeFilter && pad->GetAttribute() == PAD_ATTRIB::CONN )
619 {
620 if( pad->IsAperturePad() != aSrcPad.IsAperturePad() )
621 continue;
622 }
623
624 commit.Modify( pad );
625
626 // Apply source pad settings to this pad
627 pad->ImportSettingsFrom( aSrcPad );
628 }
629 }
630}
631
632
634{
635 PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>();
636 const PCB_SELECTION& selection = selTool->GetSelection();
637
638 if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
639 {
640 PAD* srcPad = static_cast<PAD*>( selection[0] );
641
642 if( FOOTPRINT* footprint = srcPad->GetParentFootprint() )
643 {
644 frame()->SetMsgPanel( footprint );
645
647 int dialogRet = dlg.ShowModal();
648
649 if( dialogRet == wxID_CANCEL )
650 return 0;
651
652 const bool edit_Same_Modules = (dialogRet == 1);
653
654 BOARD_COMMIT commit( frame() );
655
656 doPushPadProperties( *getModel<BOARD>(), *srcPad, commit, edit_Same_Modules, dlg.GetPadShapeFilter(),
658 dlg.GetPadTypeFilter() );
659
660 commit.Push( _( "Push Pad Settings" ) );
661
663 frame()->Refresh();
664 }
665 }
666
667 return 0;
668}
669
670
677static std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> GetSequentialPadNumberingParams( wxWindow* aFrame )
678{
679 // Persistent settings for the pad enumeration dialog.
680 static SEQUENTIAL_PAD_ENUMERATION_PARAMS s_lastUsedParams;
681
682 DIALOG_ENUM_PADS settingsDlg( aFrame, s_lastUsedParams );
683
684 if( settingsDlg.ShowModal() != wxID_OK )
685 return std::nullopt;
686
687 return s_lastUsedParams;
688}
689
690
692{
694 return 0;
695
696 if( !board()->GetFirstFootprint() || board()->GetFirstFootprint()->Pads().empty() )
697 return 0;
698
699 GENERAL_COLLECTOR collector;
700 GENERAL_COLLECTORS_GUIDE guide = frame()->GetCollectorsGuide();
701 guide.SetIgnoreFPTextOnBack( true );
702 guide.SetIgnoreFPTextOnFront( true );
703 guide.SetIgnoreFPValues( true );
704 guide.SetIgnoreFPReferences( true );
705
706 const std::optional<SEQUENTIAL_PAD_ENUMERATION_PARAMS> params = GetSequentialPadNumberingParams( frame() );
707
708 // Cancelled or otherwise failed to get any useful parameters
709 if( !params )
710 return 0;
711
712 int seqPadNum = params->m_start_number;
713
714 std::deque<int> storedPadNumbers;
715 std::map<wxString, std::pair<int, wxString>> oldNumbers;
716
718
719 SCOPED_TOOL_PUSHER raii( frame(), aEvent );
720
721 VECTOR2I oldMousePos; // store the previous mouse cursor position, during mouse drag
722 std::list<PAD*> selectedPads;
723 BOARD_COMMIT commit( frame() );
724 bool isFirstPoint = true; // make sure oldMousePos is initialized at least once
725 std::deque<PAD*> pads = board()->GetFirstFootprint()->Pads();
726 MAGNETIC_SETTINGS mag_settings;
727
728 mag_settings.graphics = false;
729 mag_settings.tracks = MAGNETIC_OPTIONS::NO_EFFECT;
731
732 PCB_GRID_HELPER grid( m_toolMgr, &mag_settings );
733
734 grid.SetSnap( true );
735 grid.SetUseGrid( false );
736
737 auto setCursor =
738 [&]()
739 {
741 };
742
743 KIGFX::VIEW* view = m_toolMgr->GetView();
744 RENDER_SETTINGS* settings = view->GetPainter()->GetSettings();
745 const std::set<int>& activeLayers = settings->GetHighContrastLayers();
746 bool isHighContrast = settings->GetHighContrast();
747
748 view->SyncLayerVisibilityCache(); // Required for ViewGetLOD() calls.
749
750 auto checkVisibility =
751 [&]( BOARD_ITEM* item )
752 {
753 if( !view->IsVisible( item ) )
754 return false;
755
756 for( PCB_LAYER_ID layer : item->GetLayerSet() )
757 {
758 if( ( isHighContrast && activeLayers.count( layer ) ) || view->IsLayerVisible( layer ) )
759 {
760 if( item->ViewGetLOD( layer, view ) < view->GetScale() )
761 return true;
762 }
763 }
764
765 return false;
766 };
767
768 for( PAD* pad : board()->GetFirstFootprint()->Pads() )
769 {
770 if( checkVisibility( pad ) )
771 pads.push_back( pad );
772 }
773
774 Activate();
775 // Must be done after Activate() so that it gets set into the correct context
776 getViewControls()->ShowCursor( true );
778 // Set initial cursor
779 setCursor();
780
781 STATUS_TEXT_POPUP statusPopup( frame() );
782
783 // Callable lambda to construct the pad number string for the given value
784 const auto constructPadNumber =
785 [&]( int aValue )
786 {
787 return wxString::Format( wxT( "%s%d" ), params->m_prefix.value_or( "" ), aValue );
788 };
789
790 // Callable lambda to set the popup text for the given pad value
791 const auto setPopupTextForValue =
792 [&]( int aValue )
793 {
794 const wxString msg = _( "Click on pad %s\n"
795 "Press <esc> to cancel all; double-click to finish" );
796 statusPopup.SetText( wxString::Format( msg, constructPadNumber( aValue ) ) );
797 };
798
799 setPopupTextForValue( seqPadNum );
800 statusPopup.Popup();
801 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
802 canvas()->SetStatusPopup( statusPopup.GetPanel() );
803
804 while( TOOL_EVENT* evt = Wait() )
805 {
806 setCursor();
807
809 VECTOR2I cursorPos = grid.SnapToPad( mousePos, pads );
810 getViewControls()->ForceCursorPosition( true, cursorPos );
811
812 if( evt->IsCancelInteractive() )
813 {
815 commit.Revert();
816 break;
817 }
818 else if( evt->IsActivate() )
819 {
820 commit.Push( _( "Renumber Pads" ) );
821 break;
822 }
823 else if( evt->IsDrag( BUT_LEFT ) || evt->IsClick( BUT_LEFT ) )
824 {
825 selectedPads.clear();
826
827 // Be sure the old cursor mouse position was initialized:
828 if( isFirstPoint )
829 {
830 oldMousePos = mousePos;
831 isFirstPoint = false;
832 }
833
834 // wxWidgets deliver mouse move events not frequently enough, resulting in skipping
835 // pads if the user moves cursor too fast. To solve it, create a line that approximates
836 // the mouse move and search pads that are on the line.
837 int distance = ( mousePos - oldMousePos ).EuclideanNorm();
838 // Search will be made every 0.1 mm:
839 int segments = distance / int( 0.1 * pcbIUScale.IU_PER_MM ) + 1;
840 const VECTOR2I line_step( ( mousePos - oldMousePos ) / segments );
841
842 collector.Empty();
843
844 for( int j = 0; j < segments; ++j )
845 {
846 VECTOR2I testpoint( mousePos.x - j * line_step.x, mousePos.y - j * line_step.y );
847 collector.Collect( board(), { PCB_PAD_T }, testpoint, guide );
848
849 for( int i = 0; i < collector.GetCount(); ++i )
850 {
851 PAD* pad = static_cast<PAD*>( collector[i] );
852
853 if( pad->CanHaveNumber() && checkVisibility( pad ) )
854 selectedPads.push_back( pad );
855 }
856 }
857
858 selectedPads.unique();
859
860 for( PAD* pad : selectedPads )
861 {
862 // If pad was not selected, then enumerate it
863 if( !pad->IsSelected() )
864 {
865 commit.Modify( pad );
866
867 // Rename pad and store the old name
868 int newval;
869
870 if( storedPadNumbers.size() > 0 )
871 {
872 newval = storedPadNumbers.front();
873 storedPadNumbers.pop_front();
874 }
875 else
876 {
877 newval = seqPadNum;
878 seqPadNum += params->m_step;
879 }
880
881 const wxString newNumber = constructPadNumber( newval );
882 oldNumbers[newNumber] = { newval, pad->GetNumber() };
883 pad->SetNumber( newNumber );
884 SetLastPadNumber( newNumber );
885 pad->SetSelected();
886 getView()->Update( pad );
887
888 // Ensure the popup text shows the correct next value
889 if( storedPadNumbers.size() > 0 )
890 newval = storedPadNumbers.front();
891 else
892 newval = seqPadNum;
893
894 setPopupTextForValue( newval );
895 }
896
897 // ... or restore the old name if it was enumerated and clicked again
898 else if( pad->IsSelected() && evt->IsClick( BUT_LEFT ) )
899 {
900 auto it = oldNumbers.find( pad->GetNumber() );
901 wxASSERT( it != oldNumbers.end() );
902
903 if( it != oldNumbers.end() )
904 {
905 storedPadNumbers.push_back( it->second.first );
906 pad->SetNumber( it->second.second );
907 SetLastPadNumber( it->second.second );
908 oldNumbers.erase( it );
909
910 const int newval = storedPadNumbers.front();
911 setPopupTextForValue( newval );
912 }
913
914 pad->ClearSelected();
915 getView()->Update( pad );
916 }
917 }
918 }
919 else if( evt->IsDblClick( BUT_LEFT ) || evt->IsAction( &ACTIONS::cursorDblClick ) )
920 {
921 commit.Push( _( "Renumber Pads" ) );
922 break;
923 }
924 else if( evt->IsClick( BUT_RIGHT ) )
925 {
926 m_menu->ShowContextMenu( selection() );
927 }
928 else
929 {
930 evt->SetPassEvent();
931 }
932
933 // Prepare the next loop by updating the old cursor mouse position
934 // to this last mouse cursor position
935 oldMousePos = mousePos;
936 statusPopup.Move( KIPLATFORM::UI::GetMousePosition() + wxPoint( 20, 20 ) );
937 }
938
939 for( PAD* p : board()->GetFirstFootprint()->Pads() )
940 {
941 p->ClearSelected();
942 getView()->Update( p );
943 }
944
945 canvas()->SetStatusPopup( nullptr );
946 statusPopup.Hide();
947
950 return 0;
951}
952
953
954int PAD_TOOL::PlacePad( const TOOL_EVENT& aEvent )
955{
956 // When creating a new pad (in FP editor) we can use a new pad number or the last entered pad number
957 // neednewPadNumber = true to create a new pad number, false to use the last entered pad number
958 static bool neednewPadNumber;
959
961 return 0;
962
963 if( !board()->GetFirstFootprint() )
964 return 0;
965
966 struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
967 {
968 PAD_PLACER( PAD_TOOL* aPadTool, PCB_BASE_EDIT_FRAME* aFrame, PAD_MASTER_PROVIDER& aMasterPadProvider,
969 PAD_MASTER_PROVIDER::TYPE aMasterType, std::unique_ptr<PAD> aSelectedPadCopy ) :
970 m_padTool( aPadTool ),
971 m_gridHelper( aPadTool->GetManager(), aFrame->GetMagneticItemsSettings() ),
972 m_masterPadProvider( aMasterPadProvider ),
973 m_masterPadType( aMasterType ),
974 m_selectedPadCopy( std::move( aSelectedPadCopy ) )
975 {
976 m_frame = aFrame;
977 m_board = aFrame->GetBoard();
978
979 neednewPadNumber = true; // Use a new pad number when creating a pad by default
980 }
981
982 ~PAD_PLACER() = default;
983
984 std::unique_ptr<BOARD_ITEM> CreateItem() override
985 {
986 std::unique_ptr<PAD> pad = std::make_unique<PAD>( m_board->GetFirstFootprint() );
987
988 const PAD master = m_masterPadProvider.GetMasterPad( m_masterPadType, m_board->GetFirstFootprint(),
989 m_selectedPadCopy.get() );
990
991 pad->ImportSettingsFrom( master );
992
993 if( pad->CanHaveNumber() )
994 {
995 wxString padNumber = m_padTool->GetLastPadNumber();
996
997 // Use the last entered pad number when recreating a pad without using the
998 // previously created pad, and a new number when creating a really new pad
999 if( neednewPadNumber )
1000 padNumber = m_board->GetFirstFootprint()->GetNextPadNumber( padNumber );
1001
1002 pad->SetNumber( padNumber );
1003 m_padTool->SetLastPadNumber( padNumber );
1004
1005 // If a pad is recreated and the previously created was not placed, use
1006 // the last entered pad number
1007 neednewPadNumber = false;
1008 }
1009
1010 return pad;
1011 }
1012
1013 bool PlaceItem( BOARD_ITEM *aItem, BOARD_COMMIT& aCommit ) override
1014 {
1015 PAD* pad = dynamic_cast<PAD*>( aItem );
1016 // We are using this pad number.
1017 // therefore use a new pad number for a newly created pad
1018 neednewPadNumber = true;
1019
1020 if( pad )
1021 {
1022 m_masterPadProvider.RecordNewMasterPad( *pad );
1023 aCommit.Add( aItem );
1024 return true;
1025 }
1026
1027 return false;
1028 }
1029
1030 void SnapItem( BOARD_ITEM *aItem ) override
1031 {
1032 m_gridHelper.SetSnap( !( m_modifiers & MD_SHIFT ) );
1033 m_gridHelper.SetUseGrid( !( m_modifiers & MD_CTRL ) );
1034
1035 if( !m_gridHelper.GetSnap() )
1036 return;
1037
1038 MAGNETIC_SETTINGS* settings = m_frame->GetMagneticItemsSettings();
1039 PAD* pad = static_cast<PAD*>( aItem );
1040 VECTOR2I position = m_padTool->getViewControls()->GetMousePosition();
1041 KIGFX::VIEW_CONTROLS* viewControls = m_padTool->getViewControls();
1042 std::vector<BOARD_ITEM*> ignored_items( 1, pad );
1043
1044 if( settings->pads == MAGNETIC_OPTIONS::NO_EFFECT )
1045 {
1046 PADS& pads = m_board->GetFirstFootprint()->Pads();
1047 ignored_items.insert( ignored_items.end(), pads.begin(), pads.end() );
1048 }
1049
1050 if( !settings->graphics )
1051 {
1052 DRAWINGS& graphics = m_board->GetFirstFootprint()->GraphicalItems();
1053 ignored_items.insert( ignored_items.end(), graphics.begin(), graphics.end() );
1054 }
1055
1056 VECTOR2I cursorPos = m_gridHelper.ResolveSnap( position, LSET::AllLayersMask(),
1057 GRID_CURRENT, ignored_items ).position;
1058 viewControls->ForceCursorPosition( true, cursorPos );
1059 aItem->SetPosition( cursorPos );
1060 }
1061
1062 PAD_TOOL* m_padTool;
1063 PCB_GRID_HELPER m_gridHelper;
1065 PAD_MASTER_PROVIDER::TYPE m_masterPadType;
1066 std::unique_ptr<PAD> m_selectedPadCopy;
1067 };
1068
1069 const PAD_MASTER_PROVIDER::TYPE masterPadType = PAD_MASTER_PROVIDER::TypeFromAction( aEvent );
1070
1071 // The interactive placement helper clears the selection, so do this beforehand.
1072 std::unique_ptr<PAD> selectedPad;
1073
1074 if( PCB_SELECTION_TOOL* selTool = m_toolMgr->GetTool<PCB_SELECTION_TOOL>() )
1075 {
1076 for( const EDA_ITEM* item : selTool->GetSelection() )
1077 {
1078 // Choose a pad from the selection if available
1079 if( item->Type() == PCB_PAD_T )
1080 {
1081 selectedPad = std::make_unique<PAD>( *static_cast<const PAD*>( item ) );
1082 break;
1083 }
1084 }
1085 }
1086
1087 PAD_PLACER placer( this, frame(), *m_masterPadProvider, masterPadType, std::move( selectedPad ) );
1088
1089 doInteractiveItemPlacement( aEvent, &placer, _( "Place pad" ),
1091
1092 return 0;
1093}
1094
1095
1096int PAD_TOOL::EditPad( const TOOL_EVENT& aEvent )
1097{
1098 if( !m_isFootprintEditor )
1099 return 0;
1100
1101 Activate();
1102
1103 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
1104 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
1105 PCB_SELECTION& selection = m_toolMgr->GetTool<PCB_SELECTION_TOOL>()->GetSelection();
1106
1107 if( m_editPad != niluuid )
1108 {
1109 if( PAD* pad = dynamic_cast<PAD*>( frame()->ResolveItem( m_editPad ) ) )
1110 {
1111 BOARD_COMMIT commit( frame() );
1112 commit.Modify( pad );
1113
1114 std::vector<PCB_SHAPE*> mergedShapes = RecombinePad( pad, false );
1115
1116 for( PCB_SHAPE* shape : mergedShapes )
1117 commit.Remove( shape );
1118
1119 commit.Push( _( "Edit Pad" ) );
1120 }
1121
1123 }
1124 else if( selection.Size() == 1 && selection[0]->Type() == PCB_PAD_T )
1125 {
1126 PAD* pad = static_cast<PAD*>( selection[0] );
1127 BOARD_COMMIT commit( frame() );
1128
1129 commit.Modify( pad );
1130 explodePad( pad, commit );
1131 commit.Push( _( "Edit Pad" ) );
1132
1133 m_toolMgr->RunAction( ACTIONS::selectionClear );
1134 frame()->SetActiveLayer( pad->GetPrincipalLayer() );
1135
1136 settings->m_PadEditModePad = pad;
1138 }
1139
1140 if( m_editPad == niluuid )
1142
1143 return 0;
1144}
1145
1146
1148{
1149 PAD* flaggedPad = nullptr;
1150 KIID flaggedPadId = niluuid;
1151
1152 for( FOOTPRINT* fp : board()->Footprints() )
1153 {
1154 for( PAD* pad : fp->Pads() )
1155 {
1156 if( pad->IsEntered() )
1157 {
1158 flaggedPad = pad;
1159 flaggedPadId = pad->m_Uuid;
1160 break;
1161 }
1162 }
1163 }
1164
1165 if( flaggedPadId != m_editPad )
1166 {
1167 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
1168 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
1169
1170 m_editPad = flaggedPadId;
1171 settings->m_PadEditModePad = flaggedPad;
1172
1173 if( flaggedPad )
1175 else
1177 }
1178
1179 return 0;
1180}
1181
1182
1184{
1185 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
1186 WX_INFOBAR* infoBar = frame()->GetInfoBar();
1187 wxString msg;
1188
1190 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1191 {
1192 return dynamic_cast<PAD*>( aItem ) != nullptr;
1193 } );
1194
1196
1198 {
1200 frame()->SetDisplayOptions( opts );
1201 }
1202
1203 if( PCB_ACTIONS::explodePad.GetHotKey() == PCB_ACTIONS::recombinePad.GetHotKey() )
1204 {
1205 msg.Printf( _( "Pad Edit Mode. Press %s again to exit." ),
1207 }
1208 else
1209 {
1210 msg.Printf( _( "Pad Edit Mode. Press %s to exit." ),
1212 }
1213
1214 infoBar->RemoveAllButtons();
1215 infoBar->ShowMessage( msg, wxICON_INFORMATION );
1216}
1217
1218
1220{
1221 KIGFX::PCB_PAINTER* painter = static_cast<KIGFX::PCB_PAINTER*>( view()->GetPainter() );
1222 PCB_RENDER_SETTINGS* settings = painter->GetSettings();
1223 PCB_DISPLAY_OPTIONS opts = frame()->GetDisplayOptions();
1224
1225 settings->m_PadEditModePad = nullptr;
1226
1228 {
1230 frame()->SetDisplayOptions( opts );
1231 }
1232
1233 // Note: KIGFX::REPAINT isn't enough for things that go from invisible to visible as
1234 // they won't be found in the view layer's itemset for re-painting.
1236 [&]( KIGFX::VIEW_ITEM* aItem ) -> bool
1237 {
1238 return dynamic_cast<PAD*>( aItem ) != nullptr;
1239 } );
1240
1241 // Refresh now (otherwise there's an uncomfortably long pause while the infoBar
1242 // closes before refresh).
1243 canvas()->ForceRefresh();
1244
1245 frame()->GetInfoBar()->Dismiss();
1246}
1247
1248
1250{
1251 auto explodePrimitives =
1252 [&]( PCB_LAYER_ID padstackStorageLayer, PCB_LAYER_ID targetBoardLayer )
1253 {
1254 if( aPad->GetShape( padstackStorageLayer ) == PAD_SHAPE::CUSTOM )
1255 {
1256 for( const std::shared_ptr<PCB_SHAPE>& primitive : aPad->GetPrimitives( padstackStorageLayer ) )
1257 {
1258 PCB_SHAPE* shape = static_cast<PCB_SHAPE*>( primitive->Duplicate( true, &aCommit ) );
1259
1260 shape->SetParent( board()->GetFirstFootprint() );
1261 shape->Rotate( VECTOR2I( 0, 0 ), aPad->GetOrientation() );
1262 shape->Move( aPad->ShapePos( padstackStorageLayer ) );
1263 shape->SetLayer( targetBoardLayer );
1264
1265 if( shape->IsProxyItem() && shape->GetShape() == SHAPE_T::SEGMENT )
1266 {
1267 if( aPad->GetLocalThermalSpokeWidthOverride().has_value() )
1268 shape->SetWidth( aPad->GetLocalThermalSpokeWidthOverride().value() );
1269 else
1271 }
1272
1273 aCommit.Add( shape );
1274 }
1275
1276 aPad->SetShape( padstackStorageLayer, aPad->GetAnchorPadShape( padstackStorageLayer ) );
1277 aPad->DeletePrimitivesList( padstackStorageLayer );
1278 }
1279 };
1280
1281 if( aPad->Padstack().Mode() == PADSTACK::MODE::NORMAL )
1282 {
1283 explodePrimitives( PADSTACK::ALL_LAYERS, aPad->GetPrincipalLayer() );
1284 }
1285 else
1286 {
1288 [&]( PCB_LAYER_ID layer )
1289 {
1290 explodePrimitives( layer, layer );
1291 } );
1292 }
1293
1294 aPad->SetFlags( ENTERED );
1295 m_editPad = aPad->m_Uuid;
1296}
1297
1298
1299std::vector<PCB_SHAPE*> PAD_TOOL::RecombinePad( PAD* aPad, bool aIsDryRun )
1300{
1301 int maxError = board()->GetDesignSettings().m_MaxError;
1302
1303 // Don't leave an object in the point editor that might no longer exist after recombining.
1304 m_toolMgr->RunAction( ACTIONS::selectionClear );
1305
1306 return aPad->Recombine( aIsDryRun, maxError );
1307}
1308
1309
1310int PAD_TOOL::PadTable( const TOOL_EVENT& aEvent )
1311{
1313 return 0;
1314
1316
1317 if( !footprint )
1318 return 0;
1319
1321 dlg.ShowQuasiModal();
1322
1323 return 0;
1324}
1325
1326
constexpr EDA_IU_SCALE pcbIUScale
Definition base_units.h:128
#define DEFAULT_PAD_DRILL_DIAMETER_MM
#define DEFAULT_PAD_APERTURE_WIDTH_MM
#define DEFAULT_PAD_THT_WIDTH_MM
#define DEFAULT_PAD_APERTURE_HEIGHT_MM
#define DEFAULT_PAD_SMD_WIDTH_MM
#define DEFAULT_PAD_SMD_HEIGHT_MM
#define DEFAULT_PAD_THT_HEIGHT_MM
HIGH_CONTRAST_MODE
Determine how inactive layers should be displayed.
@ NORMAL
Inactive layers are shown normally (no high-contrast mode)
@ DIMMED
Inactive layers are dimmed (old high-contrast mode)
static TOOL_ACTION cancelInteractive
Definition actions.h:69
static TOOL_ACTION cursorDblClick
Definition actions.h:178
static TOOL_ACTION selectionClear
Clear the current selection.
Definition actions.h:221
void Push(const wxString &aMessage=wxEmptyString, int aCommitFlags=0) override
Execute the changes.
void Revert() override
Revert the commit by restoring the modified items state.
A base class for any item which can be embedded within the BOARD container class, and therefore insta...
Definition board_item.h:99
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
Definition board.h:411
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
Definition board.h:713
const FOOTPRINTS & Footprints() const
Definition board.h:465
BOARD_DESIGN_SETTINGS & GetDesignSettings()
Definition board.cpp:1318
void Empty()
Clear the list.
Definition collector.h:87
int GetCount() const
Return the number of objects in the list.
Definition collector.h:79
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
Definition commit.h:86
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:102
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
Definition commit.h:74
void AddItem(const TOOL_ACTION &aAction, const SELECTION_CONDITION &aCondition, int aOrder=ANY_ORDER)
Add a menu entry to run a TOOL_ACTION on selected items.
void AddSeparator(int aOrder=ANY_ORDER)
Add a separator to the menu.
static DELETED_BOARD_ITEM * GetInstance()
Definition board_item.h:666
Dialog for enumerating pads.
int ShowModal() override
void ForceRefresh()
Force a redraw.
void SetCurrentCursor(KICURSOR aCursor)
Set the current cursor shape for this panel.
void SetStatusPopup(wxWindow *aPopup)
A base class for most all the KiCad significant classes used in schematics and boards.
Definition eda_item.h:98
virtual void SetPosition(const VECTOR2I &aPos)
Definition eda_item.h:349
void SetFlags(EDA_ITEM_FLAGS aMask)
Definition eda_item.h:158
const KIID m_Uuid
Definition eda_item.h:599
KICAD_T Type() const
Returns the type of object.
Definition eda_item.h:110
virtual void SetParent(EDA_ITEM *aParent)
Definition eda_item.cpp:153
SHAPE_T GetShape() const
Definition eda_shape.h:178
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
Definition actions.h:354
static const TOOL_EVENT UndoRedoPostEvent
Definition actions.h:371
EDA_ANGLE GetOrientation() const
Definition footprint.h:382
std::deque< PAD * > & Pads()
Definition footprint.h:355
const LIB_ID & GetFPID() const
Definition footprint.h:417
A general implementation of a COLLECTORS_GUIDE.
Definition collectors.h:320
void SetIgnoreFPTextOnFront(bool ignore)
Definition collectors.h:413
void SetIgnoreFPTextOnBack(bool ignore)
Definition collectors.h:407
void SetIgnoreFPReferences(bool ignore)
Definition collectors.h:455
void SetIgnoreFPValues(bool ignore)
Definition collectors.h:449
Used when the right click button is pressed, or when the select tool is in effect.
Definition collectors.h:203
void Collect(BOARD_ITEM *aItem, const std::vector< KICAD_T > &aScanList, const VECTOR2I &aRefPos, const COLLECTORS_GUIDE &aGuide)
Scan a BOARD_ITEM using this class's Inspector method, which does the collection.
Contains methods for drawing PCB-specific items.
virtual PCB_RENDER_SETTINGS * GetSettings() override
Return a pointer to current settings that are going to be used when drawing items.
PCB specific render settings.
Definition pcb_painter.h:94
Container for all the knowledge about how graphical objects are drawn on any output surface/device.
const std::set< int > GetHighContrastLayers() const
Returns the set of currently high-contrast layers.
An interface for classes handling user events controlling the view behavior such as zooming,...
virtual void ForceCursorPosition(bool aEnabled, const VECTOR2D &aPosition=VECTOR2D(0, 0))
Place the cursor immediately at a given point.
virtual void ShowCursor(bool aEnabled)
Enable or disables display of cursor.
virtual VECTOR2D GetMousePosition(bool aWorldCoordinates=true) const =0
Return the current mouse pointer position.
An abstract base class for deriving all objects that can be added to a VIEW.
Definition view_item.h:82
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
Definition view.h:68
virtual void Update(const VIEW_ITEM *aItem, int aUpdateFlags) const
For dynamic VIEWs, inform the associated VIEW that the graphical representation of this item has chan...
Definition view.cpp:2630
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
Definition view.h:242
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
Definition view.cpp:2491
Definition kiid.h:46
LSET is a set of PCB_LAYER_IDs.
Definition lset.h:37
static const LSET & AllLayersMask()
Definition lset.cpp:637
void ForEachUniqueLayer(const std::function< void(PCB_LAYER_ID)> &aMethod) const
Runs the given callable for each active unique copper layer in this padstack, meaning F_Cu for MODE::...
LSET RelevantShapeLayers(const PADSTACK &aOther) const
Returns the set of layers that must be considered if checking one padstack against another.
@ NORMAL
Shape is the same on all layers.
Definition padstack.h:175
MODE Mode() const
Definition padstack.h:351
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
Definition padstack.h:184
PAD GetMasterPad(TYPE aType, const FOOTPRINT *aFootprint, const PAD *aSelectedPad) const
Get the master pad for the given type, footprint, and selected pad.
Definition pad_tool.cpp:91
TYPE resolveAutoType(const std::vector< const PAD * > &aFpPads, const PAD *aSelectedPad) const
Resolve the type a TYPE::AUTO request actually wants.
Definition pad_tool.cpp:354
std::unordered_map< TYPE, KIID > m_lastRealPadsForType
Definition pad_tool.cpp:378
PAD_MASTER_PROVIDER()=default
std::unique_ptr< PAD > MakeDefaultPad(PAD_MASTER_PROVIDER::TYPE aMasterType) const
Create a default pad for the given master pad type when there is no more obvious source.
Definition pad_tool.cpp:160
TYPE m_lastType
Persistent store of the last pad type.
Definition pad_tool.cpp:381
static std::optional< TYPE > TypeFromPad(const PAD &aPad)
Determine the master pad type from the given pad.
Definition pad_tool.cpp:313
void RecordNewMasterPad(const PAD &aPlacedPad)
Record the given pad as the most recently placed pad of its type.
Definition pad_tool.cpp:282
static TYPE TypeFromAction(const TOOL_EVENT &aEvent)
Definition pad_tool.cpp:294
void RecordMasterPad(const PAD &aPad)
Record aPad as the template for the next pad of its type placed.
Definition pad_tool.cpp:402
void Reset(RESET_REASON aReason) override
React to model/view changes.
Definition pad_tool.cpp:408
int OnUndoRedo(const TOOL_EVENT &aEvent)
HIGH_CONTRAST_MODE m_previousHighContrastMode
Definition pad_tool.h:103
void setTransitions() override
Bind handlers to corresponding TOOL_ACTIONs.
int EditPad(const TOOL_EVENT &aEvent)
Enter/exit WYSIWYG pad shape editing.
void ExitPadEditMode()
KIID m_editPad
Definition pad_tool.h:104
std::unique_ptr< PAD_MASTER_PROVIDER > m_masterPadProvider
When pads are created this provides the master pad settings.
Definition pad_tool.h:107
int copyPadSettings(const TOOL_EVENT &aEvent)
Copy pad settings from a pad to the tool's buffer pad.
Definition pad_tool.cpp:518
void enterPadEditMode()
int pastePadProperties(const TOOL_EVENT &aEvent)
Apply pad settings from the buffer pad to a pad.
Definition pad_tool.cpp:492
int PlacePad(const TOOL_EVENT &aEvent)
Place a pad in footprint editor.
Definition pad_tool.cpp:954
int EnumeratePads(const TOOL_EVENT &aEvent)
Tool for quick pad enumeration.
Definition pad_tool.cpp:691
void explodePad(PAD *aPad, BOARD_COMMIT &aCommit)
std::unique_ptr< PAD > m_bufferPad
The "buffer" pad that holds the settings applied by "Paste Pad Properties".
Definition pad_tool.h:110
int PadTable(const TOOL_EVENT &aEvent)
bool Init() override
Basic initialization.
Definition pad_tool.cpp:430
void SetLastPadNumber(const wxString &aPadNumber)
Definition pad_tool.h:67
std::vector< PCB_SHAPE * > RecombinePad(PAD *aPad, bool aIsDryRun)
Recombine an exploded pad (or one produced with overlapping polygons in an older version).
bool InPadEditMode()
Definition pad_tool.h:63
wxString m_lastPadNumber
Definition pad_tool.h:101
int pushPadSettings(const TOOL_EVENT &aEvent)
Push pad settings from a pad to other pads on board or footprint.
Definition pad_tool.cpp:633
Definition pad.h:61
bool IsAperturePad() const
Definition pad.h:589
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
Definition pad.h:579
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
Definition pad.h:375
PAD_ATTRIB GetAttribute() const
Definition pad.h:582
static LSET PTHMask()
layer set for a through hole pad
Definition pad.cpp:620
const wxString & GetNumber() const
Definition pad.h:143
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
Definition pad.h:196
std::vector< PCB_SHAPE * > Recombine(bool aIsDryRun, int aMaxError)
Recombines the pad with other graphical shapes in the footprint.
Definition pad.cpp:3142
PCB_LAYER_ID GetPrincipalLayer() const
Definition pad.cpp:669
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
Definition pad.cpp:641
void DeletePrimitivesList(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Clear the basic shapes list.
Definition pad.cpp:3461
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
Definition pad.h:205
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
Definition pad.cpp:297
void ImportSettingsFrom(const PAD &aMasterPad)
Import the pad settings from aMasterPad.
Definition pad.cpp:2921
const PADSTACK & Padstack() const
Definition pad.h:331
static LSET ConnSMDMask()
layer set for a SMD pad on Front layer used for edge board connectors
Definition pad.cpp:634
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
Definition pad.cpp:1672
static LSET ApertureMask()
layer set for an aperture pad
Definition pad.cpp:648
static LSET SMDMask()
layer set for a SMD pad on Front layer
Definition pad.cpp:627
std::optional< int > GetLocalThermalSpokeWidthOverride() const
Definition pad.h:763
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
Definition pad.cpp:1825
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
Definition pad.h:219
static TOOL_ACTION recombinePad
static TOOL_ACTION enumeratePads
Tool for quick pad enumeration.
static TOOL_ACTION placePasteAperturePad
static TOOL_ACTION pushPadSettings
Copy the current pad's settings to other pads in the footprint or on the board.
static TOOL_ACTION mirrorH
Mirroring of selected items.
static TOOL_ACTION copyPadSettings
Copy the selected pad's settings to the board design settings.
static TOOL_ACTION placePad
Activation of the drawing tool (placing a PAD)
static TOOL_ACTION placeNpthPad
static TOOL_ACTION padTable
static TOOL_ACTION properties
Activation of the edit tool.
static TOOL_ACTION explodePad
static TOOL_ACTION applyPadSettings
Copy the default pad settings to the selected pad.
static TOOL_ACTION placeThtPad
static TOOL_ACTION placeSmdPad
static TOOL_ACTION mirrorV
static TOOL_ACTION flip
Flipping of selected objects.
static TOOL_ACTION rotateCw
Rotation of selected objects.
static TOOL_ACTION rotateCcw
Common, abstract interface for edit frames.
virtual MAGNETIC_SETTINGS * GetMagneticItemsSettings()
BOARD * GetBoard() const
HIGH_CONTRAST_MODE m_ContrastModeDisplay
How inactive layers are displayed.
virtual KIGFX::PCB_VIEW * GetView() const override
Return a pointer to the KIGFX::VIEW instance used in the panel.
The selection tool: currently supports:
PCB_SELECTION & GetSelection()
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetWidth(int aWidth) override
bool IsProxyItem() const override
Definition pcb_shape.h:155
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
T * frame() const
KIGFX::PCB_VIEW * view() const
PCB_TOOL_BASE(TOOL_ID aId, const std::string &aName)
Constructor.
BOARD * board() const
PCB_DRAW_PANEL_GAL * canvas() const
@ IPO_FLIP
Handle flip action in the loop by calling the item's flip method.
@ IPO_ROTATE
Handle the rotate action in the loop by calling the item's rotate method.
@ IPO_SINGLE_CLICK
Create an item immediately on placement starting, otherwise show the pencil cursor until the item is ...
@ IPO_REPEAT
Allow repeat placement of the item.
void doInteractiveItemPlacement(const TOOL_EVENT &aTool, INTERACTIVE_PLACER_BASE *aPlacer, const wxString &aCommitMessage, int aOptions=IPO_ROTATE|IPO_FLIP|IPO_REPEAT)
Helper function for performing a common interactive idiom: wait for a left click, place an item there...
const PCB_SELECTION & selection() const
FOOTPRINT * footprint() const
static SELECTION_CONDITION HasType(KICAD_T aType)
Create a functor that tests if among the selected items there is at least one of a given type.
static SELECTION_CONDITION Count(int aNumber)
Create a functor that tests if the number of selected items is equal to the value given as parameter.
static bool ShowAlways(const SELECTION &aSelection)
The default condition function (always returns true).
static SELECTION_CONDITION OnlyTypes(std::vector< KICAD_T > aTypes)
Create a functor that tests if the selected items are only of given types.
wxWindow * GetPanel()
virtual void Popup(wxWindow *aFocus=nullptr)
virtual void Move(const wxPoint &aWhere)
Extension of STATUS_POPUP for displaying a single line text.
void SetText(const wxString &aText)
Display a text.
TOOL_MANAGER * GetManager() const
Return the instance of TOOL_MANAGER that takes care of the tool.
Definition tool_base.h:142
T * getEditFrame() const
Return the application window object, casted to requested user type.
Definition tool_base.h:182
T * getModel() const
Return the model object if it matches the requested type.
Definition tool_base.h:195
KIGFX::VIEW_CONTROLS * getViewControls() const
Return the instance of VIEW_CONTROLS object used in the application.
Definition tool_base.cpp:40
TOOL_MANAGER * m_toolMgr
Definition tool_base.h:220
KIGFX::VIEW * getView() const
Return the instance of KIGFX::VIEW object used in the application.
Definition tool_base.cpp:34
RESET_REASON
Determine the reason of reset for a tool.
Definition tool_base.h:74
@ MODEL_RELOAD
Model changes (the sheet for a schematic)
Definition tool_base.h:76
Generic, UI-independent tool event.
Definition tool_event.h:167
bool IsAction(const TOOL_ACTION *aAction) const
Test if the event contains an action issued upon activation of the given TOOL_ACTION.
void Go(int(T::*aStateFunc)(const TOOL_EVENT &), const TOOL_EVENT_LIST &aConditions=TOOL_EVENT(TC_ANY, TA_ANY))
Define which state (aStateFunc) to go when a certain event arrives (aConditions).
TOOL_MENU & GetToolMenu()
std::unique_ptr< TOOL_MENU > m_menu
The functions below are not yet implemented - their interface may change.
TOOL_EVENT * Wait(const TOOL_EVENT_LIST &aEventList=TOOL_EVENT(TC_ANY, TA_ANY))
Suspend execution of the tool until an event specified in aEventList arrives.
void Activate()
Run the tool.
CONDITIONAL_MENU & GetMenu()
Definition tool_menu.cpp:40
A modified version of the wxInfoBar class that allows us to:
Definition wx_infobar.h:77
void RemoveAllButtons()
Remove all the buttons that have been added by the user.
void ShowMessage(const wxString &aMessage, int aFlags=wxICON_INFORMATION) override
Show the info bar with the provided message and icon.
@ ARROW
Definition cursors.h:43
@ BULLSEYE
Definition cursors.h:55
static bool empty(const wxTextEntryBase *aCtrl)
#define _(s)
static constexpr EDA_ANGLE ANGLE_90
Definition eda_angle.h:474
#define ENTERED
indicates a group has been entered
@ SEGMENT
Definition eda_shape.h:57
static const std::vector< KICAD_T > padTypes
@ GRID_CURRENT
Definition grid_helper.h:57
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
NORMAL
Follows standard pretty-printing rules.
KIID niluuid(0)
PCB_LAYER_ID
A quick note on layer IDs:
Definition layer_ids.h:56
@ F_Mask
Definition layer_ids.h:93
@ F_Cu
Definition layer_ids.h:60
This file contains miscellaneous commonly used macros and functions.
@ REPAINT
Item needs to be redrawn.
Definition view_item.h:54
@ ALL
All except INITIAL_ADD.
Definition view_item.h:55
wxPoint GetMousePosition()
Returns the mouse position in screen coordinates.
double GetDefaultIpcRoundingRatio(const PAD &aPad, PCB_LAYER_ID aLayer)
Get a sensible default for a rounded rectangle pad's rounding ratio.
Definition pad_utils.cpp:37
STL namespace.
static bool padSizesMatch(const PAD &aPad1, const PAD &aPad2)
Check if the sizes of two pads match on all relevant layers.
Definition pad_tool.cpp:548
static void doPushPadProperties(BOARD &board, const PAD &aSrcPad, BOARD_COMMIT &commit, bool aSameFootprints, bool aPadShapeFilter, bool aPadSizeFilter, bool aPadOrientFilter, bool aPadLayerFilter, bool aPadTypeFilter)
Definition pad_tool.cpp:562
static std::optional< SEQUENTIAL_PAD_ENUMERATION_PARAMS > GetSequentialPadNumberingParams(wxWindow *aFrame)
Prompts the user for parameters for sequential pad numbering.
Definition pad_tool.cpp:677
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
Definition padstack.h:104
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
Definition padstack.h:106
@ SMD
Smd pad, appears on the solder paste layer (default)
Definition padstack.h:100
@ PTH
Plated through hole pad.
Definition padstack.h:99
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
Definition padstack.h:101
@ ROUNDRECT
Definition padstack.h:58
@ RECTANGLE
Definition padstack.h:55
#define DEFAULT_PAD_NPTH_DIAMETER_MM
std::deque< PAD * > PADS
std::deque< BOARD_ITEM * > DRAWINGS
static float distance(const SFVEC2UI &a, const SFVEC2UI &b)
std::function< bool(const SELECTION &)> SELECTION_CONDITION
Functor type that checks a specific condition for selected items.
int StrNumCmp(const wxString &aString1, const wxString &aString2, CMP_T aCaseSensitivity)
Compare two strings with alphanumerical content.
MAGNETIC_OPTIONS tracks
MAGNETIC_OPTIONS pads
Parameters for sequential pad numbering.
@ MD_CTRL
Definition tool_event.h:140
@ MD_SHIFT
Definition tool_event.h:139
@ BUT_LEFT
Definition tool_event.h:128
@ BUT_RIGHT
Definition tool_event.h:129
@ PCB_PAD_T
class PAD, a pad in a footprint
Definition typeinfo.h:79
VECTOR2< int32_t > VECTOR2I
Definition vector2d.h:708
VECTOR2< double > VECTOR2D
Definition vector2d.h:707
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM
Definition zones.h:29