26#include <unordered_map>
93 std::vector<const PAD*> fpPads;
97 fpPads.assign( aFootprint->
Pads().begin(), aFootprint->
Pads().end() );
99 const auto reverseNumberSorter =
100 [](
const PAD* a,
const PAD* b )
106 std::sort( fpPads.begin(), fpPads.end(), reverseNumberSorter );
112 if( aType == TYPE::AUTO )
117 if( aSelectedPad &&
TypeFromPad( *aSelectedPad ) == aType )
118 return *aSelectedPad;
124 for(
const PAD*
pad : fpPads )
126 if(
pad->m_Uuid == lastRealPadIt->second )
130 if( !padType || *padType != aType )
141 for(
const PAD*
pad : fpPads )
146 if( padType && *padType == aType )
162 std::unique_ptr<PAD>
pad = std::make_unique<PAD>(
nullptr );
167 switch( aMasterType )
169 case PAD_MASTER_PROVIDER::TYPE::THT:
187 case PAD_MASTER_PROVIDER::TYPE::SMD:
201 case PAD_MASTER_PROVIDER::TYPE::NPTH:
213 pad->SetDrillSize( size );
217 case PAD_MASTER_PROVIDER::TYPE::PASTE:
218 case PAD_MASTER_PROVIDER::TYPE::MASK:
222 if( aMasterType == PAD_MASTER_PROVIDER::TYPE::PASTE )
234 case PAD_MASTER_PROVIDER::TYPE::CONNECTOR:
246 case PAD_MASTER_PROVIDER::TYPE::NON_COMPONENT:
260 case PAD_MASTER_PROVIDER::TYPE::AUTO:
262 wxFAIL_MSG(
"AUTO pad type should not be used for default pad creation" );
284 std::optional<TYPE> padType =
TypeFromPad( aPlacedPad );
334 return TYPE::CONNECTOR;
336 return TYPE::NON_COMPONENT;
358 std::optional<TYPE> selectedType =
TypeFromPad( *aSelectedPad );
360 return *selectedType;
366 for(
const PAD*
pad : aFpPads )
420 frame()->SetDisplayOptions( opts );
423 frame()->GetInfoBar()->Dismiss();
445 auto explodeCondition =
451 auto recombineCondition =
472 auto& ctxMenu =
m_menu->GetMenu();
476 ctxMenu.AddSeparator( 1 );
509 commit.
Push(
_(
"Paste Pad Properties" ) );
530 const PAD& selPad =
static_cast<const PAD&
>( *item );
563 bool aPadShapeFilter,
bool aPadSizeFilter,
bool aPadOrientFilter,
bool aPadLayerFilter,
564 bool aPadTypeFilter )
572 if( !aSameFootprints && ( footprint != refFootprint ) )
575 if( footprint->GetFPID() != refFootprint->
GetFPID() )
578 for(
PAD*
pad : footprint->Pads() )
580 if( aPadShapeFilter )
582 bool shapesMatch =
true;
585 pad->Padstack().ForEachUniqueLayer(
588 if(
pad->GetShape( aLayer ) != aSrcPad.
GetShape( aLayer ) )
595 if( aSrcPad.
GetShape( aLayer ) !=
pad->GetShape( aLayer ) )
603 EDA_ANGLE padAngle =
pad->GetOrientation() - footprint->GetOrientation();
608 if( aPadOrientFilter && ( padAngle != srcPadAngle ) )
611 if( aPadLayerFilter && (
pad->GetLayerSet() != aSrcPad.
GetLayerSet() ) )
614 if( aPadTypeFilter && (
pad->GetAttribute() != aSrcPad.
GetAttribute() ) )
627 pad->ImportSettingsFrom( aSrcPad );
649 if( dialogRet == wxID_CANCEL )
652 const bool edit_Same_Modules = (dialogRet == 1);
660 commit.
Push(
_(
"Push Pad Settings" ) );
687 return s_lastUsedParams;
696 if( !
board()->GetFirstFootprint() ||
board()->GetFirstFootprint()->Pads().
empty() )
712 int seqPadNum = params->m_start_number;
714 std::deque<int> storedPadNumbers;
715 std::map<wxString, std::pair<int, wxString>> oldNumbers;
722 std::list<PAD*> selectedPads;
724 bool isFirstPoint =
true;
734 grid.SetSnap(
true );
735 grid.SetUseGrid(
false );
748 view->SyncLayerVisibilityCache();
750 auto checkVisibility =
753 if( !
view->IsVisible( item ) )
758 if( ( isHighContrast && activeLayers.count( layer ) ) ||
view->IsLayerVisible( layer ) )
760 if( item->ViewGetLOD( layer,
view ) <
view->GetScale() )
768 for(
PAD*
pad :
board()->GetFirstFootprint()->Pads() )
770 if( checkVisibility(
pad ) )
771 pads.push_back(
pad );
784 const auto constructPadNumber =
787 return wxString::Format( wxT(
"%s%d" ), params->m_prefix.value_or(
"" ), aValue );
791 const auto setPopupTextForValue =
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 ) ) );
799 setPopupTextForValue( seqPadNum );
812 if( evt->IsCancelInteractive() )
818 else if( evt->IsActivate() )
820 commit.
Push(
_(
"Renumber Pads" ) );
825 selectedPads.clear();
830 oldMousePos = mousePos;
831 isFirstPoint =
false;
837 int distance = ( mousePos - oldMousePos ).EuclideanNorm();
840 const VECTOR2I line_step( ( mousePos - oldMousePos ) / segments );
844 for(
int j = 0; j < segments; ++j )
846 VECTOR2I testpoint( mousePos.
x - j * line_step.
x, mousePos.
y - j * line_step.
y );
849 for(
int i = 0; i < collector.
GetCount(); ++i )
851 PAD*
pad =
static_cast<PAD*
>( collector[i] );
853 if(
pad->CanHaveNumber() && checkVisibility(
pad ) )
854 selectedPads.push_back(
pad );
858 selectedPads.unique();
860 for(
PAD*
pad : selectedPads )
863 if( !
pad->IsSelected() )
870 if( storedPadNumbers.size() > 0 )
872 newval = storedPadNumbers.front();
873 storedPadNumbers.pop_front();
878 seqPadNum += params->m_step;
881 const wxString newNumber = constructPadNumber( newval );
882 oldNumbers[newNumber] = { newval,
pad->GetNumber() };
883 pad->SetNumber( newNumber );
889 if( storedPadNumbers.size() > 0 )
890 newval = storedPadNumbers.front();
894 setPopupTextForValue( newval );
898 else if(
pad->IsSelected() && evt->IsClick(
BUT_LEFT ) )
900 auto it = oldNumbers.find(
pad->GetNumber() );
901 wxASSERT( it != oldNumbers.end() );
903 if( it != oldNumbers.end() )
905 storedPadNumbers.push_back( it->second.first );
906 pad->SetNumber( it->second.second );
908 oldNumbers.erase( it );
910 const int newval = storedPadNumbers.front();
911 setPopupTextForValue( newval );
914 pad->ClearSelected();
921 commit.
Push(
_(
"Renumber Pads" ) );
935 oldMousePos = mousePos;
939 for(
PAD* p :
board()->GetFirstFootprint()->Pads() )
958 static bool neednewPadNumber;
963 if( !
board()->GetFirstFootprint() )
970 m_padTool( aPadTool ),
973 m_masterPadType( aMasterType ),
974 m_selectedPadCopy( std::move( aSelectedPadCopy ) )
979 neednewPadNumber =
true;
982 ~PAD_PLACER() =
default;
984 std::unique_ptr<BOARD_ITEM> CreateItem()
override
986 std::unique_ptr<PAD>
pad = std::make_unique<PAD>( m_board->GetFirstFootprint() );
989 m_selectedPadCopy.get() );
991 pad->ImportSettingsFrom( master );
993 if(
pad->CanHaveNumber() )
995 wxString padNumber = m_padTool->GetLastPadNumber();
999 if( neednewPadNumber )
1000 padNumber = m_board->GetFirstFootprint()->GetNextPadNumber( padNumber );
1002 pad->SetNumber( padNumber );
1003 m_padTool->SetLastPadNumber( padNumber );
1007 neednewPadNumber =
false;
1018 neednewPadNumber =
true;
1023 aCommit.
Add( aItem );
1032 m_gridHelper.SetSnap( !( m_modifiers &
MD_SHIFT ) );
1033 m_gridHelper.SetUseGrid( !( m_modifiers &
MD_CTRL ) );
1035 if( !m_gridHelper.GetSnap() )
1040 VECTOR2I position = m_padTool->getViewControls()->GetMousePosition();
1042 std::vector<BOARD_ITEM*> ignored_items( 1,
pad );
1046 PADS& pads = m_board->GetFirstFootprint()->Pads();
1047 ignored_items.insert( ignored_items.end(), pads.begin(), pads.end() );
1052 DRAWINGS& graphics = m_board->GetFirstFootprint()->GraphicalItems();
1053 ignored_items.insert( ignored_items.end(), graphics.begin(), graphics.end() );
1066 std::unique_ptr<PAD> m_selectedPadCopy;
1072 std::unique_ptr<PAD> selectedPad;
1076 for(
const EDA_ITEM* item : selTool->GetSelection() )
1081 selectedPad = std::make_unique<PAD>( *
static_cast<const PAD*
>( item ) );
1119 commit.
Push(
_(
"Edit Pad" ) );
1131 commit.
Push(
_(
"Edit Pad" ) );
1134 frame()->SetActiveLayer(
pad->GetPrincipalLayer() );
1149 PAD* flaggedPad =
nullptr;
1154 for(
PAD*
pad : fp->Pads() )
1156 if(
pad->IsEntered() )
1159 flaggedPadId =
pad->m_Uuid;
1192 return dynamic_cast<PAD*
>( aItem ) !=
nullptr;
1200 frame()->SetDisplayOptions( opts );
1205 msg.Printf(
_(
"Pad Edit Mode. Press %s again to exit." ),
1210 msg.Printf(
_(
"Pad Edit Mode. Press %s to exit." ),
1230 frame()->SetDisplayOptions( opts );
1238 return dynamic_cast<PAD*
>( aItem ) !=
nullptr;
1245 frame()->GetInfoBar()->Dismiss();
1251 auto explodePrimitives =
1256 for(
const std::shared_ptr<PCB_SHAPE>& primitive : aPad->
GetPrimitives( padstackStorageLayer ) )
1258 PCB_SHAPE* shape =
static_cast<PCB_SHAPE*
>( primitive->Duplicate(
true, &aCommit ) );
1263 shape->
SetLayer( targetBoardLayer );
1273 aCommit.
Add( shape );
1290 explodePrimitives( layer, layer );
1306 return aPad->
Recombine( aIsDryRun, maxError );
constexpr EDA_IU_SCALE pcbIUScale
#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
static TOOL_ACTION cursorDblClick
static TOOL_ACTION selectionClear
Clear the current selection.
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...
FOOTPRINT * GetParentFootprint() const
Information pertinent to a Pcbnew printed circuit board.
FOOTPRINT * GetFirstFootprint() const
Get the first footprint on the board or nullptr.
const FOOTPRINTS & Footprints() const
BOARD_DESIGN_SETTINGS & GetDesignSettings()
void Empty()
Clear the list.
int GetCount() const
Return the number of objects in the list.
COMMIT & Remove(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Remove a new item from the model.
COMMIT & Modify(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr, RECURSE_MODE aRecurse=RECURSE_MODE::NO_RECURSE)
Modify a given item in the model.
COMMIT & Add(EDA_ITEM *aItem, BASE_SCREEN *aScreen=nullptr)
Add a new item to the model.
static DELETED_BOARD_ITEM * GetInstance()
Dialog for enumerating pads.
bool GetPadShapeFilter() const
bool GetPadSizeFilter() const
bool GetPadLayerFilter() const
bool GetPadTypeFilter() const
bool GetPadOrientFilter() const
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.
virtual void SetPosition(const VECTOR2I &aPos)
void SetFlags(EDA_ITEM_FLAGS aMask)
KICAD_T Type() const
Returns the type of object.
virtual void SetParent(EDA_ITEM *aParent)
static const TOOL_EVENT SelectedItemsModified
Selected item had a property changed (except movement)
static const TOOL_EVENT UndoRedoPostEvent
A general implementation of a COLLECTORS_GUIDE.
void SetIgnoreFPTextOnFront(bool ignore)
void SetIgnoreFPTextOnBack(bool ignore)
void SetIgnoreFPReferences(bool ignore)
void SetIgnoreFPValues(bool ignore)
Used when the right click button is pressed, or when the select tool is in effect.
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.
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.
bool GetHighContrast() const
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.
Hold a (potentially large) number of VIEW_ITEMs and renders them on a graphics device provided by the...
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...
PAINTER * GetPainter() const
Return the painter object used by the view for drawing VIEW_ITEM objects.
void UpdateAllItemsConditionally(int aUpdateFlags, std::function< bool(VIEW_ITEM *)> aCondition)
Update items in the view according to the given flags and condition.
LSET is a set of PCB_LAYER_IDs.
static const LSET & AllLayersMask()
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.
static constexpr PCB_LAYER_ID ALL_LAYERS
! The layer identifier to use for the single defintion on normal padstacks
PAD GetMasterPad(TYPE aType, const FOOTPRINT *aFootprint, const PAD *aSelectedPad) const
Get the master pad for the given type, footprint, and selected pad.
TYPE resolveAutoType(const std::vector< const PAD * > &aFpPads, const PAD *aSelectedPad) const
Resolve the type a TYPE::AUTO request actually wants.
std::unordered_map< TYPE, KIID > m_lastRealPadsForType
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.
TYPE m_lastType
Persistent store of the last pad type.
static std::optional< TYPE > TypeFromPad(const PAD &aPad)
Determine the master pad type from the given pad.
void RecordNewMasterPad(const PAD &aPlacedPad)
Record the given pad as the most recently placed pad of its type.
static TYPE TypeFromAction(const TOOL_EVENT &aEvent)
bool IsAperturePad() const
LSET GetLayerSet() const override
Return a std::bitset of all layers on which the item physically resides.
const std::vector< std::shared_ptr< PCB_SHAPE > > & GetPrimitives(PCB_LAYER_ID aLayer) const
Accessor to the basic shape list for custom-shaped pads.
PAD_ATTRIB GetAttribute() const
static LSET PTHMask()
layer set for a through hole pad
const wxString & GetNumber() const
void SetShape(PCB_LAYER_ID aLayer, PAD_SHAPE aShape)
Set the new shape of this pad.
std::vector< PCB_SHAPE * > Recombine(bool aIsDryRun, int aMaxError)
Recombines the pad with other graphical shapes in the footprint.
PCB_LAYER_ID GetPrincipalLayer() const
static LSET UnplatedHoleMask()
layer set for a mechanical unplated through hole pad
void DeletePrimitivesList(PCB_LAYER_ID aLayer=UNDEFINED_LAYER)
Clear the basic shapes list.
PAD_SHAPE GetShape(PCB_LAYER_ID aLayer) const
VECTOR2I GetSize(PCB_LAYER_ID aLayer) const
void ImportSettingsFrom(const PAD &aMasterPad)
Import the pad settings from aMasterPad.
const PADSTACK & Padstack() const
static LSET ConnSMDMask()
layer set for a SMD pad on Front layer used for edge board connectors
EDA_ANGLE GetOrientation() const
Return the rotation angle of the pad.
static LSET ApertureMask()
layer set for an aperture pad
static LSET SMDMask()
layer set for a SMD pad on Front layer
std::optional< int > GetLocalThermalSpokeWidthOverride() const
VECTOR2I ShapePos(PCB_LAYER_ID aLayer) const
PAD_SHAPE GetAnchorPadShape(PCB_LAYER_ID aLayer) const
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()
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.
void Rotate(const VECTOR2I &aRotCentre, const EDA_ANGLE &aAngle) override
Rotate this object.
void SetWidth(int aWidth) override
bool IsProxyItem() const override
void SetLayer(PCB_LAYER_ID aLayer) override
Set the layer this item is on.
void Move(const VECTOR2I &aMoveVector) override
Move this object.
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.
A modified version of the wxInfoBar class that allows us to:
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.
static bool empty(const wxTextEntryBase *aCtrl)
static constexpr EDA_ANGLE ANGLE_90
#define ENTERED
indicates a group has been entered
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
NORMAL
Follows standard pretty-printing rules.
PCB_LAYER_ID
A quick note on layer IDs:
This file contains miscellaneous commonly used macros and functions.
@ REPAINT
Item needs to be redrawn.
@ ALL
All except INITIAL_ADD.
double GetDefaultIpcRoundingRatio(const PAD &aPad, PCB_LAYER_ID aLayer)
Get a sensible default for a rounded rectangle pad's rounding ratio.
@ NPTH
like PAD_PTH, but not plated mechanical use only, no connection allowed
@ NON_COMPONENT
Pad with no hole that does not connect to a physical component, but rather provides a connection poin...
@ SMD
Smd pad, appears on the solder paste layer (default)
@ PTH
Plated through hole pad.
@ CONN
Like smd, does not appear on the solder paste layer (default) Note: also has a special attribute in G...
#define DEFAULT_PAD_NPTH_DIAMETER_MM
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.
Parameters for sequential pad numbering.
@ PCB_PAD_T
class PAD, a pad in a footprint
VECTOR2< int32_t > VECTOR2I
VECTOR2< double > VECTOR2D
#define ZONE_THERMAL_RELIEF_COPPER_WIDTH_MM