From 37b723d8ae68043a8163b66f6bc5681ced3462ee Mon Sep 17 00:00:00 2001 From: Jeff Young Date: Sun, 3 May 2020 08:59:05 +0100 Subject: [PATCH] Fix pad name increment to use last edited pad. Fixes https://gitlab.com/kicad/code/kicad/issues/1882 (cherry picked from commit 56946f4db11c6381e3b439ecff0799e8d54ac497) --- include/class_board_item.h | 4 --- pcbnew/array_creator.cpp | 2 +- pcbnew/block_footprint_editor.cpp | 17 ++++++++---- pcbnew/class_board_item.cpp | 29 -------------------- pcbnew/class_module.cpp | 27 ++++++++---------- pcbnew/class_module.h | 10 ++----- pcbnew/class_pad.cpp | 11 -------- pcbnew/class_pad.h | 12 -------- pcbnew/dialogs/dialog_pad_properties.cpp | 10 +++++-- pcbnew/footprint_edit_frame.h | 2 ++ pcbnew/tools/edit_tool.cpp | 15 +++++++++- pcbnew/tools/footprint_editor_tools.cpp | 35 ++++++++++++++++++++++-- pcbnew/tools/footprint_editor_tools.h | 4 +++ 13 files changed, 86 insertions(+), 92 deletions(-) diff --git a/include/class_board_item.h b/include/class_board_item.h index 47c67d16b9..9f79827f40 100644 --- a/include/class_board_item.h +++ b/include/class_board_item.h @@ -67,14 +67,10 @@ enum STROKE_T */ class BOARD_ITEM : public EDA_ITEM { - protected: PCB_LAYER_ID m_Layer; - static int getNextNumberInSequence( const std::set& aSeq, bool aFillSequenceGaps ); - public: - BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) : EDA_ITEM( aParent, idtype ), m_Layer( F_Cu ) { diff --git a/pcbnew/array_creator.cpp b/pcbnew/array_creator.cpp index 953532feaf..45cc8c8b19 100644 --- a/pcbnew/array_creator.cpp +++ b/pcbnew/array_creator.cpp @@ -106,7 +106,7 @@ void ARRAY_CREATOR::Invoke() { // Don't bother incrementing pads: the module won't update // until commit, so we can only do this once - new_item.reset( module->Duplicate( item, false ) ); + new_item.reset( module->Duplicate( item ) ); } else { diff --git a/pcbnew/block_footprint_editor.cpp b/pcbnew/block_footprint_editor.cpp index 4cd50fde16..d8c3a1cdc8 100644 --- a/pcbnew/block_footprint_editor.cpp +++ b/pcbnew/block_footprint_editor.cpp @@ -53,7 +53,9 @@ #include #include - +#include +#include +#include #define BLOCK_COLOR BROWN @@ -72,7 +74,6 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx static int MarkItemsInBloc( MODULE* module, EDA_RECT& Rect ); static void ClearMarkItems( MODULE* module ); -static void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ); static void MoveMarkedItems( MODULE* module, wxPoint offset ); static void DeleteMarkedItems( MODULE* module ); @@ -452,7 +453,7 @@ static void DrawMovingBlockOutlines( EDA_DRAW_PANEL* aPanel, wxDC* aDC, const wx /* Copy marked items, at new position = old position + offset */ -void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ) +void FOOTPRINT_EDIT_FRAME::CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ) { if( module == NULL ) return; @@ -473,8 +474,14 @@ void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ) NewPad->SetFlags( SELECTED ); module->PadsList().PushFront( NewPad ); - if( aIncrement ) - NewPad->IncrementPadName( true, true ); + if( aIncrement && PAD_NAMING::PadCanHaveName( *NewPad ) ) + { + MODULE_EDITOR_TOOLS* modEdit = m_toolManager->GetTool(); + wxString padName = modEdit->GetLastPadName(); + padName = module->GetNextPadName( padName ); + modEdit->SetLastPadName( padName ); + NewPad->SetName( padName ); + } } BOARD_ITEM* newItem; diff --git a/pcbnew/class_board_item.cpp b/pcbnew/class_board_item.cpp index 9af3ee7569..8554259cfa 100644 --- a/pcbnew/class_board_item.cpp +++ b/pcbnew/class_board_item.cpp @@ -95,35 +95,6 @@ void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const } -int BOARD_ITEM::getNextNumberInSequence( const std::set& aSeq, bool aFillSequenceGaps) -{ - if( aSeq.empty() ) - return 1; - - // By default go to the end of the sequence - int candidate = *aSeq.rbegin(); - - // Filling in gaps in pad numbering - if( aFillSequenceGaps ) - { - // start at the beginning - candidate = *aSeq.begin(); - - for( auto it : aSeq ) - { - if( it - candidate > 1 ) - break; - - candidate = it; - } - } - - ++candidate; - - return candidate; -} - - void BOARD_ITEM::DeleteStructure() { auto parent = GetParent(); diff --git a/pcbnew/class_module.cpp b/pcbnew/class_module.cpp index 928c7d92b5..b3fc288bef 100644 --- a/pcbnew/class_module.cpp +++ b/pcbnew/class_module.cpp @@ -1244,9 +1244,8 @@ void MODULE::SetOrientation( double newangle ) CalculateBoundingBox(); } -BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, - bool aIncrementPadNumbers, - bool aAddToModule ) + +BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, bool aAddToModule ) { BOARD_ITEM* new_item = NULL; D_PAD* new_pad = NULL; @@ -1305,29 +1304,25 @@ BOARD_ITEM* MODULE::Duplicate( const BOARD_ITEM* aItem, break; } - if( aIncrementPadNumbers && new_pad && !new_pad->IsAperturePad() ) - { - new_pad->IncrementPadName( true, true ); - } - return new_item; } -wxString MODULE::GetNextPadName( bool aFillSequenceGaps ) const +wxString MODULE::GetNextPadName( const wxString& aLastPadName ) const { - std::set usedNumbers; + std::set usedNames; // Create a set of used pad numbers for( D_PAD* pad = PadsList(); pad; pad = pad->Next() ) - { - int padNumber = GetTrailingInt( pad->GetName() ); - usedNumbers.insert( padNumber ); - } + usedNames.insert( pad->GetName() ); - const int nextNum = getNextNumberInSequence( usedNumbers, aFillSequenceGaps ); + wxString prefix = UTIL::GetReferencePrefix( aLastPadName ); + int num = GetTrailingInt( aLastPadName ); - return wxString::Format( wxT( "%i" ), nextNum ); + while( usedNames.count( wxString::Format( "%s%d", prefix, num ) ) ) + num++; + + return wxString::Format( "%s%d", prefix, num ); } diff --git a/pcbnew/class_module.h b/pcbnew/class_module.h index 7f1df4b58e..15a9fc8f4c 100644 --- a/pcbnew/class_module.h +++ b/pcbnew/class_module.h @@ -555,12 +555,8 @@ public: /** * Function GetNextPadName * returns the next available pad name in the module - * - * @param aFillSequenceGaps true if the numbering should "fill in" gaps in - * the sequence, else return the highest value + 1 - * @return the next available pad name */ - wxString GetNextPadName( bool aFillSequenceGaps ) const; + wxString GetNextPadName( const wxString& aLastPadName ) const; double GetArea( int aPadding = 0 ) const; @@ -578,9 +574,7 @@ public: * Duplicate a given item within the module, without adding to the board * @return the new item, or NULL if the item could not be duplicated */ - BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, - bool aIncrementPadNumbers, - bool aAddToModule = false ); + BOARD_ITEM* Duplicate( const BOARD_ITEM* aItem, bool aAddToModule = false ); /** * Function Add3DModel diff --git a/pcbnew/class_pad.cpp b/pcbnew/class_pad.cpp index 5bd8c017cd..7d6c5bfd65 100644 --- a/pcbnew/class_pad.cpp +++ b/pcbnew/class_pad.cpp @@ -562,17 +562,6 @@ wxPoint D_PAD::ShapePos() const } -bool D_PAD::IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps ) -{ - bool skip = aSkipUnconnectable && ( GetAttribute() == PAD_ATTRIB_HOLE_NOT_PLATED ); - - if( !skip ) - SetName( GetParent()->GetNextPadName( aFillSequenceGaps ) ); - - return !skip; -} - - void D_PAD::CopyNetlistSettings( D_PAD* aPad, bool aCopyLocalSettings ) { // Don't do anything foolish like trying to copy to yourself. diff --git a/pcbnew/class_pad.h b/pcbnew/class_pad.h index 1f5f5cae63..9b2d233b15 100644 --- a/pcbnew/class_pad.h +++ b/pcbnew/class_pad.h @@ -192,18 +192,6 @@ public: return m_name; } - /** - * Function IncrementPadName - * - * Increments the pad name to the next available name in the module. - * - * @param aSkipUnconnectable skips any pads that are not connectable (for example NPTH) - * @param aFillSequenceGaps if true, the next reference in a sequence - * like A1,A3,A4 will be A2. If false, it will be A5. - * @return pad name incremented - */ - bool IncrementPadName( bool aSkipUnconnectable, bool aFillSequenceGaps ); - bool PadNameEqual( const D_PAD* other ) const { return m_name == other->m_name; // hide tricks behind sensible API diff --git a/pcbnew/dialogs/dialog_pad_properties.cpp b/pcbnew/dialogs/dialog_pad_properties.cpp index 991f96ddac..9e08346560 100644 --- a/pcbnew/dialogs/dialog_pad_properties.cpp +++ b/pcbnew/dialogs/dialog_pad_properties.cpp @@ -42,7 +42,8 @@ #include #include #include - +#include +#include #include #include @@ -97,7 +98,12 @@ static const LSET std_pad_layers[] = void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* aPad ) { DIALOG_PAD_PROPERTIES dlg( this, aPad ); - dlg.ShowQuasiModal(); // QuasiModal required for NET_SELECTOR + + if( dlg.ShowQuasiModal() == wxID_OK ) // QuasiModal required for NET_SELECTOR + { + MODULE_EDITOR_TOOLS* fpTools = m_toolManager->GetTool(); + fpTools->SetLastPadName( aPad->GetName() ); + } } diff --git a/pcbnew/footprint_edit_frame.h b/pcbnew/footprint_edit_frame.h index 1f821b3f5f..5797a13fb9 100644 --- a/pcbnew/footprint_edit_frame.h +++ b/pcbnew/footprint_edit_frame.h @@ -283,6 +283,8 @@ public: */ virtual bool HandleBlockEnd( wxDC* DC ) override; + void CopyMarkedItems( MODULE* module, wxPoint offset, bool aIncrement ); + BOARD_ITEM* ModeditLocateAndDisplay( int aHotKeyCode = 0 ); /// Return the LIB_ID of the part selected in the footprint or the part being edited. diff --git a/pcbnew/tools/edit_tool.cpp b/pcbnew/tools/edit_tool.cpp index 3fbfa38e8e..2bdcc8eea8 100644 --- a/pcbnew/tools/edit_tool.cpp +++ b/pcbnew/tools/edit_tool.cpp @@ -39,6 +39,8 @@ #include #include #include +#include +#include #include #include #include @@ -1126,7 +1128,18 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent ) if( m_editModules ) { - dupe_item = editFrame->GetBoard()->m_Modules->Duplicate( orig_item, increment ); + MODULE* editModule = editFrame->GetBoard()->m_Modules; + dupe_item = editModule->Duplicate( orig_item ); + + if( increment && item->Type() == PCB_PAD_T + && PAD_NAMING::PadCanHaveName( *static_cast( dupe_item ) ) ) + { + MODULE_EDITOR_TOOLS* modEdit = m_toolMgr->GetTool(); + wxString padName = modEdit->GetLastPadName(); + padName = editModule->GetNextPadName( padName ); + modEdit->SetLastPadName( padName ); + static_cast( dupe_item )->SetName( padName ); + } } else { diff --git a/pcbnew/tools/footprint_editor_tools.cpp b/pcbnew/tools/footprint_editor_tools.cpp index 45d464d05c..123c03b9dd 100644 --- a/pcbnew/tools/footprint_editor_tools.cpp +++ b/pcbnew/tools/footprint_editor_tools.cpp @@ -23,6 +23,7 @@ */ #include "footprint_editor_tools.h" +#include #include "kicad_clipboard.h" #include "selection_tool.h" #include "pcb_actions.h" @@ -93,6 +94,8 @@ MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS() void MODULE_EDITOR_TOOLS::Reset( RESET_REASON aReason ) { + if( aReason == MODEL_RELOAD ) + m_lastPadName = wxT( "1" ); } @@ -104,11 +107,28 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) struct PAD_PLACER : public INTERACTIVE_PLACER_BASE { + PAD_PLACER( MODULE_EDITOR_TOOLS* aFPEditTools ) + { + m_fpEditTools = aFPEditTools; + } + + virtual ~PAD_PLACER() + { + } + std::unique_ptr CreateItem() override { D_PAD* pad = new D_PAD ( m_board->m_Modules ); m_frame->Import_Pad_Settings( pad, false ); // use the global settings for pad - pad->IncrementPadName( true, true ); + + if( PAD_NAMING::PadCanHaveName( *pad ) ) + { + wxString padName = m_fpEditTools->GetLastPadName(); + padName = m_board->m_Modules->GetNextPadName( padName ); + pad->SetName( padName ); + m_fpEditTools->SetLastPadName( padName ); + } + return std::unique_ptr( pad ); } @@ -126,9 +146,11 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent ) return false; } + + MODULE_EDITOR_TOOLS* m_fpEditTools; }; - PAD_PLACER placer; + PAD_PLACER placer( this ); frame()->SetToolID( ID_MODEDIT_PAD_TOOL, wxCURSOR_PENCIL, _( "Add pads" ) ); @@ -481,8 +503,15 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent ) pad->SetLayerSet( D_PAD::SMDMask() ); int radius = Millimeter2iu( 0.2 ); pad->SetSize ( wxSize( radius, radius ) ); - pad->IncrementPadName( true, true ); pad->SetOrientation( 0 ); + + if( PAD_NAMING::PadCanHaveName( *pad ) ) + { + wxString padName = GetLastPadName(); + padName = board()->m_Modules->GetNextPadName( padName ); + pad->SetName( padName ); + SetLastPadName( padName ); + } } pad->SetShape ( PAD_SHAPE_CUSTOM ); diff --git a/pcbnew/tools/footprint_editor_tools.h b/pcbnew/tools/footprint_editor_tools.h index 56fb5e2ffe..dec1d8996e 100644 --- a/pcbnew/tools/footprint_editor_tools.h +++ b/pcbnew/tools/footprint_editor_tools.h @@ -82,10 +82,14 @@ public: */ int ExplodePadToShapes( const TOOL_EVENT& aEvent ); + wxString GetLastPadName() const { return m_lastPadName; } + void SetLastPadName( const wxString& aPadName ) { m_lastPadName = aPadName; } ///> Sets up handlers for various events. void setTransitions() override; +private: + wxString m_lastPadName; }; #endif