Fix pad name increment to use last edited pad.

Fixes https://gitlab.com/kicad/code/kicad/issues/1882

(cherry picked from commit 56946f4db1)
This commit is contained in:
Jeff Young 2020-05-03 08:59:05 +01:00
parent aec3649524
commit 37b723d8ae
13 changed files with 86 additions and 92 deletions

View File

@ -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<int>& aSeq, bool aFillSequenceGaps );
public:
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
{

View File

@ -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
{

View File

@ -53,7 +53,9 @@
#include <class_edge_mod.h>
#include <dialogs/dialog_move_exact.h>
#include <tool/tool_manager.h>
#include <tools/footprint_editor_tools.h>
#include <pad_naming.h>
#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<MODULE_EDITOR_TOOLS>();
wxString padName = modEdit->GetLastPadName();
padName = module->GetNextPadName( padName );
modEdit->SetLastPadName( padName );
NewPad->SetName( padName );
}
}
BOARD_ITEM* newItem;

View File

@ -95,35 +95,6 @@ void BOARD_ITEM::ViewGetLayers( int aLayers[], int& aCount ) const
}
int BOARD_ITEM::getNextNumberInSequence( const std::set<int>& 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();

View File

@ -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<int> usedNumbers;
std::set<wxString> 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 );
}

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -42,7 +42,8 @@
#include <class_module.h>
#include <pcb_painter.h>
#include <widgets/net_selector.h>
#include <tool/tool_manager.h>
#include <tools/footprint_editor_tools.h>
#include <dialog_pad_properties.h>
#include <html_messagebox.h>
@ -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<MODULE_EDITOR_TOOLS>();
fpTools->SetLastPadName( aPad->GetName() );
}
}

View File

@ -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.

View File

@ -39,6 +39,8 @@
#include <pcbnew_id.h>
#include <status_popup.h>
#include <tool/tool_manager.h>
#include <tools/footprint_editor_tools.h>
#include <pad_naming.h>
#include <view/view_controls.h>
#include <view/view.h>
#include <gal/graphics_abstraction_layer.h>
@ -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<D_PAD*>( dupe_item ) ) )
{
MODULE_EDITOR_TOOLS* modEdit = m_toolMgr->GetTool<MODULE_EDITOR_TOOLS>();
wxString padName = modEdit->GetLastPadName();
padName = editModule->GetNextPadName( padName );
modEdit->SetLastPadName( padName );
static_cast<D_PAD*>( dupe_item )->SetName( padName );
}
}
else
{

View File

@ -23,6 +23,7 @@
*/
#include "footprint_editor_tools.h"
#include <pad_naming.h>
#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<BOARD_ITEM> 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<BOARD_ITEM>( 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 );

View File

@ -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