If more than one text matches by text try layer and then position.

Fixes https://gitlab.com/kicad/code/kicad/issues/4187
This commit is contained in:
Jeff Young 2020-05-05 00:11:32 +01:00
parent e0da677d4d
commit 8df5f70c4a
3 changed files with 43 additions and 9 deletions

View File

@ -410,15 +410,49 @@ void processTextItem( const TEXTE_MODULE& aSrc, TEXTE_MODULE& aDest,
TEXTE_MODULE* getMatchingTextItem( TEXTE_MODULE* aRefItem, MODULE* aModule )
{
for( auto item : aModule->GraphicalItems() )
std::vector<TEXTE_MODULE*> candidates;
for( BOARD_ITEM* item : aModule->GraphicalItems() )
{
TEXTE_MODULE* candidate = dyn_cast<TEXTE_MODULE*>( item );
if( candidate && candidate->GetText() == aRefItem->GetText() )
return candidate;
candidates.push_back( candidate );
}
return nullptr;
if( candidates.size() == 0 )
return nullptr;
if( candidates.size() == 1 )
return candidates[0];
// Try refining the match by layer
std::vector<TEXTE_MODULE*> candidatesOnSameLayer;
for( TEXTE_MODULE* candidate : candidates )
{
if( candidate->GetLayer() == aRefItem->GetLayer() )
candidatesOnSameLayer.push_back( candidate );
}
if( candidatesOnSameLayer.size() == 1 )
return candidatesOnSameLayer[0];
// Last ditch effort: refine by position
std::vector<TEXTE_MODULE*> candidatesAtSamePos;
for( TEXTE_MODULE* candidate : candidatesOnSameLayer.size() ? candidatesOnSameLayer : candidates )
{
if( candidate->GetPos0() == aRefItem->GetPos0() )
candidatesAtSamePos.push_back( candidate );
}
if( candidatesAtSamePos.size() > 0 )
return candidatesAtSamePos[0];
else if( candidatesOnSameLayer.size() > 0 )
return candidatesOnSameLayer[0];
else
return candidates[0];
}
@ -442,7 +476,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aSrc, MODULE* aDest, BOARD_COMMIT&
aDest->SetLocked( aSrc->IsLocked() );
for( auto pad : aDest->Pads() )
for( D_PAD* pad : aDest->Pads() )
{
D_PAD* oldPad = aSrc->FindPadByName( pad->GetName() );
@ -468,7 +502,7 @@ void PCB_EDIT_FRAME::Exchange_Module( MODULE* aSrc, MODULE* aDest, BOARD_COMMIT&
resetTextLayers, resetTextEffects );
// Copy fields in accordance with the reset* flags
for( auto item : aSrc->GraphicalItems() )
for( BOARD_ITEM* item : aSrc->GraphicalItems() )
{
TEXTE_MODULE* srcItem = dyn_cast<TEXTE_MODULE*>( item );

View File

@ -30,7 +30,7 @@ DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_
m_values = new wxCheckBox( sbScope->GetStaticBox(), wxID_ANY, _("Values"), wxDefaultPosition, wxDefaultSize, 0 );
sbScope->Add( m_values, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_otherFields = new wxCheckBox( sbScope->GetStaticBox(), wxID_ANY, _("Other footprint fields"), wxDefaultPosition, wxDefaultSize, 0 );
m_otherFields = new wxCheckBox( sbScope->GetStaticBox(), wxID_ANY, _("Other footprint text items"), wxDefaultPosition, wxDefaultSize, 0 );
sbScope->Add( m_otherFields, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 );
m_footprintGraphics = new wxCheckBox( sbScope->GetStaticBox(), wxID_ANY, _("Footprint graphic items"), wxDefaultPosition, wxDefaultSize, 0 );
@ -224,7 +224,7 @@ DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_
m_grid = new wxGrid( sbAction->GetStaticBox(), wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_SIMPLE );
// Grid
m_grid->CreateGrid( 6, 7 );
m_grid->CreateGrid( 7, 7 );
m_grid->EnableEditing( false );
m_grid->EnableGridLines( true );
m_grid->EnableDragGridSize( false );

View File

@ -241,7 +241,7 @@
<property name="gripper">0</property>
<property name="hidden">0</property>
<property name="id">wxID_ANY</property>
<property name="label">Other footprint fields</property>
<property name="label">Other footprint text items</property>
<property name="max_size"></property>
<property name="maximize_button">0</property>
<property name="maximum_size"></property>
@ -2408,7 +2408,7 @@
<property name="row_label_values"></property>
<property name="row_label_vert_alignment">wxALIGN_CENTER</property>
<property name="row_sizes"></property>
<property name="rows">6</property>
<property name="rows">7</property>
<property name="show">1</property>
<property name="size"></property>
<property name="subclass"></property>