Fix pad name increment to use last edited pad.
Fixes https://gitlab.com/kicad/code/kicad/issues/1882
This commit is contained in:
parent
199bb2ffb0
commit
56946f4db1
|
@ -69,14 +69,10 @@ enum STROKE_T
|
||||||
*/
|
*/
|
||||||
class BOARD_ITEM : public EDA_ITEM
|
class BOARD_ITEM : public EDA_ITEM
|
||||||
{
|
{
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PCB_LAYER_ID m_Layer;
|
PCB_LAYER_ID m_Layer;
|
||||||
|
|
||||||
static int getNextNumberInSequence( const std::set<int>& aSeq, bool aFillSequenceGaps );
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
|
BOARD_ITEM( BOARD_ITEM* aParent, KICAD_T idtype ) :
|
||||||
EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
|
EDA_ITEM( aParent, idtype ), m_Layer( F_Cu )
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,7 +100,7 @@ void ARRAY_CREATOR::Invoke()
|
||||||
{
|
{
|
||||||
// Don't bother incrementing pads: the module won't update
|
// Don't bother incrementing pads: the module won't update
|
||||||
// until commit, so we can only do this once
|
// until commit, so we can only do this once
|
||||||
new_item = module->DuplicateItem( item, false );
|
new_item = module->DuplicateItem( item );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -85,35 +85,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()
|
void BOARD_ITEM::DeleteStructure()
|
||||||
{
|
{
|
||||||
auto parent = GetParent();
|
auto parent = GetParent();
|
||||||
|
|
|
@ -1280,8 +1280,8 @@ void MODULE::SetOrientation( double newangle )
|
||||||
CalculateBoundingBox();
|
CalculateBoundingBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aIncrementPadNumbers,
|
|
||||||
bool aAddToModule )
|
BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule )
|
||||||
{
|
{
|
||||||
BOARD_ITEM* new_item = NULL;
|
BOARD_ITEM* new_item = NULL;
|
||||||
MODULE_ZONE_CONTAINER* new_zone = NULL;
|
MODULE_ZONE_CONTAINER* new_zone = NULL;
|
||||||
|
@ -1295,9 +1295,6 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aIncrementPadNu
|
||||||
if( aAddToModule )
|
if( aAddToModule )
|
||||||
m_pads.push_back( new_pad );
|
m_pads.push_back( new_pad );
|
||||||
|
|
||||||
if( aIncrementPadNumbers && !new_pad->IsAperturePad() )
|
|
||||||
new_pad->IncrementPadName( true, true );
|
|
||||||
|
|
||||||
new_item = new_pad;
|
new_item = new_pad;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1361,20 +1358,21 @@ BOARD_ITEM* MODULE::DuplicateItem( const BOARD_ITEM* aItem, bool aIncrementPadNu
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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
|
// Create a set of used pad numbers
|
||||||
for( auto pad : m_pads )
|
for( D_PAD* pad : m_pads )
|
||||||
{
|
usedNames.insert( pad->GetName() );
|
||||||
int padNumber = GetTrailingInt( pad->GetName() );
|
|
||||||
usedNumbers.insert( padNumber );
|
|
||||||
}
|
|
||||||
|
|
||||||
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 );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -541,7 +541,7 @@ public:
|
||||||
* else return the highest value + 1
|
* else return the highest value + 1
|
||||||
* @return the next available pad name
|
* @return the next available pad name
|
||||||
*/
|
*/
|
||||||
wxString GetNextPadName( bool aFillSequenceGaps ) const;
|
wxString GetNextPadName( const wxString& aLastPadName ) const;
|
||||||
|
|
||||||
double GetArea( int aPadding = 0 ) const;
|
double GetArea( int aPadding = 0 ) const;
|
||||||
|
|
||||||
|
@ -559,8 +559,7 @@ public:
|
||||||
* Duplicate a given item within the module, without adding to the board
|
* 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
|
* @return the new item, or NULL if the item could not be duplicated
|
||||||
*/
|
*/
|
||||||
BOARD_ITEM* DuplicateItem( const BOARD_ITEM* aItem, bool aIncrementPadNumbers,
|
BOARD_ITEM* DuplicateItem( const BOARD_ITEM* aItem, bool aAddToModule = false );
|
||||||
bool aAddToModule = false );
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function Add3DModel
|
* Function Add3DModel
|
||||||
|
|
|
@ -623,17 +623,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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem, wxString* aSource ) const
|
int D_PAD::GetClearance( BOARD_CONNECTED_ITEM* aItem, wxString* aSource ) const
|
||||||
{
|
{
|
||||||
int myClearance;
|
int myClearance;
|
||||||
|
|
|
@ -189,18 +189,6 @@ public:
|
||||||
return m_pinFunction;
|
return m_pinFunction;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 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
|
bool PadNameEqual( const D_PAD* other ) const
|
||||||
{
|
{
|
||||||
return m_name == other->m_name; // hide tricks behind sensible API
|
return m_name == other->m_name; // hide tricks behind sensible API
|
||||||
|
|
|
@ -42,7 +42,8 @@
|
||||||
#include <settings/color_settings.h>
|
#include <settings/color_settings.h>
|
||||||
#include <view/view_controls.h>
|
#include <view/view_controls.h>
|
||||||
#include <widgets/net_selector.h>
|
#include <widgets/net_selector.h>
|
||||||
|
#include <tool/tool_manager.h>
|
||||||
|
#include <tools/footprint_editor_tools.h>
|
||||||
#include <advanced_config.h> // for pad property feature management
|
#include <advanced_config.h> // for pad property feature management
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,7 +98,12 @@ static const LSET std_pad_layers[] =
|
||||||
void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* aPad )
|
void PCB_BASE_FRAME::InstallPadOptionsFrame( D_PAD* aPad )
|
||||||
{
|
{
|
||||||
DIALOG_PAD_PROPERTIES dlg( this, 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() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
#include <tools/pcbnew_picker_tool.h>
|
#include <tools/pcbnew_picker_tool.h>
|
||||||
#include <tools/tool_event_utils.h>
|
#include <tools/tool_event_utils.h>
|
||||||
#include <tools/grid_helper.h>
|
#include <tools/grid_helper.h>
|
||||||
|
#include <tools/footprint_editor_tools.h>
|
||||||
|
#include <pad_naming.h>
|
||||||
#include <view/view_controls.h>
|
#include <view/view_controls.h>
|
||||||
#include <connectivity/connectivity_data.h>
|
#include <connectivity/connectivity_data.h>
|
||||||
#include <confirm.h>
|
#include <confirm.h>
|
||||||
|
@ -1135,14 +1137,24 @@ int EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||||
if( m_editModules )
|
if( m_editModules )
|
||||||
{
|
{
|
||||||
MODULE* editModule = editFrame->GetBoard()->GetFirstModule();
|
MODULE* editModule = editFrame->GetBoard()->GetFirstModule();
|
||||||
dupe_item = editModule->DuplicateItem( orig_item, increment );
|
dupe_item = editModule->DuplicateItem( 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 if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_MODULE_T )
|
else if( orig_item->GetParent() && orig_item->GetParent()->Type() == PCB_MODULE_T )
|
||||||
{
|
{
|
||||||
MODULE* parent = static_cast<MODULE*>( orig_item->GetParent() );
|
MODULE* parent = static_cast<MODULE*>( orig_item->GetParent() );
|
||||||
|
|
||||||
m_commit->Modify( parent );
|
m_commit->Modify( parent );
|
||||||
dupe_item = parent->DuplicateItem( orig_item, false, true /* add to parent */ );
|
dupe_item = parent->DuplicateItem( orig_item, true /* add to parent */ );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "footprint_editor_tools.h"
|
#include "footprint_editor_tools.h"
|
||||||
|
#include <pad_naming.h>
|
||||||
#include "kicad_clipboard.h"
|
#include "kicad_clipboard.h"
|
||||||
#include "selection_tool.h"
|
#include "selection_tool.h"
|
||||||
#include "pcb_actions.h"
|
#include "pcb_actions.h"
|
||||||
|
@ -69,6 +70,9 @@ MODULE_EDITOR_TOOLS::~MODULE_EDITOR_TOOLS()
|
||||||
void MODULE_EDITOR_TOOLS::Reset( RESET_REASON aReason )
|
void MODULE_EDITOR_TOOLS::Reset( RESET_REASON aReason )
|
||||||
{
|
{
|
||||||
m_frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
|
m_frame = getEditFrame<FOOTPRINT_EDIT_FRAME>();
|
||||||
|
|
||||||
|
if( aReason == MODEL_RELOAD )
|
||||||
|
m_lastPadName = wxT( "1" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -330,6 +334,11 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
struct PAD_PLACER : public INTERACTIVE_PLACER_BASE
|
||||||
{
|
{
|
||||||
|
PAD_PLACER( MODULE_EDITOR_TOOLS* aFPEditTools )
|
||||||
|
{
|
||||||
|
m_fpEditTools = aFPEditTools;
|
||||||
|
}
|
||||||
|
|
||||||
virtual ~PAD_PLACER()
|
virtual ~PAD_PLACER()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
@ -337,8 +346,17 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
||||||
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
std::unique_ptr<BOARD_ITEM> CreateItem() override
|
||||||
{
|
{
|
||||||
D_PAD* pad = new D_PAD( m_board->GetFirstModule() );
|
D_PAD* pad = new D_PAD( m_board->GetFirstModule() );
|
||||||
|
|
||||||
pad->ImportSettingsFrom( m_frame->GetDesignSettings().m_Pad_Master );
|
pad->ImportSettingsFrom( m_frame->GetDesignSettings().m_Pad_Master );
|
||||||
pad->IncrementPadName( true, true );
|
|
||||||
|
if( PAD_NAMING::PadCanHaveName( *pad ) )
|
||||||
|
{
|
||||||
|
wxString padName = m_fpEditTools->GetLastPadName();
|
||||||
|
padName = m_board->GetFirstModule()->GetNextPadName( padName );
|
||||||
|
pad->SetName( padName );
|
||||||
|
m_fpEditTools->SetLastPadName( padName );
|
||||||
|
}
|
||||||
|
|
||||||
return std::unique_ptr<BOARD_ITEM>( pad );
|
return std::unique_ptr<BOARD_ITEM>( pad );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -356,9 +374,11 @@ int MODULE_EDITOR_TOOLS::PlacePad( const TOOL_EVENT& aEvent )
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MODULE_EDITOR_TOOLS* m_fpEditTools;
|
||||||
};
|
};
|
||||||
|
|
||||||
PAD_PLACER placer;
|
PAD_PLACER placer( this );
|
||||||
|
|
||||||
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place pad" ),
|
doInteractiveItemPlacement( aEvent.GetCommandStr().get(), &placer, _( "Place pad" ),
|
||||||
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
IPO_REPEAT | IPO_SINGLE_CLICK | IPO_ROTATE | IPO_FLIP );
|
||||||
|
@ -513,9 +533,16 @@ int MODULE_EDITOR_TOOLS::CreatePadFromShapes( const TOOL_EVENT& aEvent )
|
||||||
pad->SetAttribute( PAD_ATTRIB_SMD );
|
pad->SetAttribute( PAD_ATTRIB_SMD );
|
||||||
pad->SetLayerSet( D_PAD::SMDMask() );
|
pad->SetLayerSet( D_PAD::SMDMask() );
|
||||||
int radius = Millimeter2iu( 0.2 );
|
int radius = Millimeter2iu( 0.2 );
|
||||||
pad->SetSize ( wxSize( radius, radius ) );
|
pad->SetSize( wxSize( radius, radius ) );
|
||||||
pad->IncrementPadName( true, true );
|
|
||||||
pad->SetOrientation( 0 );
|
pad->SetOrientation( 0 );
|
||||||
|
|
||||||
|
if( PAD_NAMING::PadCanHaveName( *pad ) )
|
||||||
|
{
|
||||||
|
wxString padName = GetLastPadName();
|
||||||
|
padName = board()->GetFirstModule()->GetNextPadName( padName );
|
||||||
|
pad->SetName( padName );
|
||||||
|
SetLastPadName( padName );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pad->SetShape ( PAD_SHAPE_CUSTOM );
|
pad->SetShape ( PAD_SHAPE_CUSTOM );
|
||||||
|
|
|
@ -99,13 +99,18 @@ public:
|
||||||
*/
|
*/
|
||||||
int ExplodePadToShapes( const TOOL_EVENT& aEvent );
|
int ExplodePadToShapes( const TOOL_EVENT& aEvent );
|
||||||
|
|
||||||
|
wxString GetLastPadName() const { return m_lastPadName; }
|
||||||
|
void SetLastPadName( const wxString& aPadName ) { m_lastPadName = aPadName; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
///> Sets up handlers for various events.
|
///> Sets up handlers for various events.
|
||||||
void setTransitions() override;
|
void setTransitions() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FOOTPRINT_EDIT_FRAME* m_frame;
|
FOOTPRINT_EDIT_FRAME* m_frame;
|
||||||
|
|
||||||
|
wxString m_lastPadName;
|
||||||
|
|
||||||
// A private clipboard for cut/copy/past of an entire footprint
|
// A private clipboard for cut/copy/past of an entire footprint
|
||||||
std::unique_ptr<MODULE> m_copiedModule;
|
std::unique_ptr<MODULE> m_copiedModule;
|
||||||
};
|
};
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
#include <tools/selection_tool.h>
|
#include <tools/selection_tool.h>
|
||||||
#include <tools/pcb_selection_conditions.h>
|
#include <tools/pcb_selection_conditions.h>
|
||||||
#include <tools/edit_tool.h>
|
#include <tools/edit_tool.h>
|
||||||
|
#include <tools/footprint_editor_tools.h>
|
||||||
#include <dialogs/dialog_enum_pads.h>
|
#include <dialogs/dialog_enum_pads.h>
|
||||||
|
|
||||||
|
|
||||||
|
@ -262,6 +263,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
m_toolMgr->RunAction( PCB_ACTIONS::selectionClear, true );
|
||||||
getViewControls()->ShowCursor( true );
|
getViewControls()->ShowCursor( true );
|
||||||
|
|
||||||
|
MODULE_EDITOR_TOOLS* fpTools = m_toolMgr->GetTool<MODULE_EDITOR_TOOLS>();
|
||||||
KIGFX::VIEW* view = m_toolMgr->GetView();
|
KIGFX::VIEW* view = m_toolMgr->GetView();
|
||||||
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
|
VECTOR2I oldCursorPos; // store the previous mouse cursor position, during mouse drag
|
||||||
std::list<D_PAD*> selectedPads;
|
std::list<D_PAD*> selectedPads;
|
||||||
|
@ -350,6 +352,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix, newval );
|
wxString newName = wxString::Format( wxT( "%s%d" ), padPrefix, newval );
|
||||||
oldNames[newName] = { newval, pad->GetName() };
|
oldNames[newName] = { newval, pad->GetName() };
|
||||||
pad->SetName( newName );
|
pad->SetName( newName );
|
||||||
|
fpTools->SetLastPadName( newName );
|
||||||
pad->SetSelected();
|
pad->SetSelected();
|
||||||
getView()->Update( pad );
|
getView()->Update( pad );
|
||||||
|
|
||||||
|
@ -372,6 +375,7 @@ int PAD_TOOL::EnumeratePads( const TOOL_EVENT& aEvent )
|
||||||
{
|
{
|
||||||
storedPadNumbers.push_back( it->second.first );
|
storedPadNumbers.push_back( it->second.first );
|
||||||
pad->SetName( it->second.second );
|
pad->SetName( it->second.second );
|
||||||
|
fpTools->SetLastPadName( it->second.second );
|
||||||
oldNames.erase( it );
|
oldNames.erase( it );
|
||||||
|
|
||||||
int newval = storedPadNumbers.front();
|
int newval = storedPadNumbers.front();
|
||||||
|
|
Loading…
Reference in New Issue