mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Preserve pin numbering when duplicating
We renumber duplicated pins but the previous order was essentially random. This keeps the numeric order of the pins on the screen, falling back to position if they are not numbered
This commit is contained in:
parent
02ec8acdb3
commit
f4bec843d4
@ -894,11 +894,42 @@ int SYMBOL_EDITOR_EDIT_TOOL::Duplicate( const TOOL_EVENT& aEvent )
|
||||
|
||||
commit.Modify( symbol, m_frame->GetScreen() );
|
||||
|
||||
EDA_ITEMS newItems;
|
||||
std::vector<EDA_ITEM*> oldItems;
|
||||
std::vector<EDA_ITEM*> newItems;
|
||||
|
||||
for( unsigned ii = 0; ii < selection.GetSize(); ++ii )
|
||||
std::copy( selection.begin(), selection.end(), std::back_inserter( oldItems ) );
|
||||
std::sort( oldItems.begin(), oldItems.end(), []( EDA_ITEM* a, EDA_ITEM* b )
|
||||
{
|
||||
SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( selection.GetItem( ii ) );
|
||||
int cmp;
|
||||
|
||||
if( a->Type() != b->Type() )
|
||||
return a->Type() < b->Type();
|
||||
|
||||
// Create the new pins in the same order as the old pins
|
||||
if( a->Type() == SCH_PIN_T )
|
||||
{
|
||||
const wxString& aNum = static_cast<SCH_PIN*>( a )->GetNumber();
|
||||
const wxString& bNum = static_cast<SCH_PIN*>( b )->GetNumber();
|
||||
|
||||
cmp = StrNumCmp( aNum, bNum );
|
||||
|
||||
// If the pin numbers are not numeric, then just number them by their position
|
||||
// on the screen.
|
||||
if( aNum.IsNumber() && bNum.IsNumber() && cmp != 0 )
|
||||
return cmp < 0;
|
||||
}
|
||||
|
||||
cmp = LexicographicalCompare( a->GetPosition(), b->GetPosition() );
|
||||
|
||||
if( cmp != 0 )
|
||||
return cmp < 0;
|
||||
|
||||
return a->m_Uuid < b->m_Uuid;
|
||||
} );
|
||||
|
||||
for( EDA_ITEM* item : oldItems )
|
||||
{
|
||||
SCH_ITEM* oldItem = static_cast<SCH_ITEM*>( item );
|
||||
SCH_ITEM* newItem = oldItem->Duplicate();
|
||||
|
||||
if( newItem->Type() == SCH_PIN_T )
|
||||
|
Loading…
x
Reference in New Issue
Block a user