diff --git a/pcbnew/dialogs/dialog_exchange_footprints.cpp b/pcbnew/dialogs/dialog_exchange_footprints.cpp index f279403850..4fd4c87090 100644 --- a/pcbnew/dialogs/dialog_exchange_footprints.cpp +++ b/pcbnew/dialogs/dialog_exchange_footprints.cpp @@ -398,15 +398,49 @@ void processTextItem( const TEXTE_MODULE& aSrc, TEXTE_MODULE& aDest, TEXTE_MODULE* getMatchingTextItem( TEXTE_MODULE* aRefItem, MODULE* aModule ) { + std::vector candidates; + for( auto iItem = aModule->GraphicalItemsList().GetFirst(); iItem; iItem = iItem->Next() ) { TEXTE_MODULE* candidate = dyn_cast( iItem ); 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 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 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]; } @@ -432,7 +466,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() ); diff --git a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.cpp b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.cpp index 52460aa345..6f815b607a 100644 --- a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.cpp +++ b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.cpp @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 1 2018) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE! @@ -40,7 +40,7 @@ DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_BASE::DIALOG_GLOBAL_EDIT_TEXT_AND_GRAPHICS_ m_boardGraphics = new wxCheckBox( sbScope->GetStaticBox(), wxID_ANY, _("PCB graphic items"), wxDefaultPosition, wxDefaultSize, 0 ); fgSizer3->Add( m_boardGraphics, 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 ); fgSizer3->Add( m_otherFields, 0, wxBOTTOM|wxRIGHT|wxLEFT, 5 ); @@ -231,7 +231,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 ); diff --git a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.fbp b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.fbp index 16db5febb0..579c778fcd 100644 --- a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.fbp +++ b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.fbp @@ -376,7 +376,7 @@ 0 0 wxID_ANY - Other footprint fields + Other footprint text items 0 @@ -2425,7 +2425,7 @@ wxALIGN_CENTER - 6 + 7 1 diff --git a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.h b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.h index b125260a2a..78206f5873 100644 --- a/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.h +++ b/pcbnew/dialogs/dialog_global_edit_text_and_graphics_base.h @@ -1,5 +1,5 @@ /////////////////////////////////////////////////////////////////////////// -// C++ code generated with wxFormBuilder (version Dec 1 2018) +// C++ code generated with wxFormBuilder (version Oct 26 2018) // http://www.wxformbuilder.org/ // // PLEASE DO *NOT* EDIT THIS FILE!